Calculating the sum of digits - c# program, DOT NET Programming

Assignment Help:

Calculating the Sum of Digits - C# Program

Hi,
Can any of you, tell me how can i calculate the sum of digits of a given number?


Related Discussions:- Calculating the sum of digits - c# program

What is a cloud, What is a cloud? A cloud is a combination of hardware,...

What is a cloud? A cloud is a combination of hardware, storage, networks, services, and interfaces that helps in delivering computing as a service. It has generally three users

We''re seeking an it candidate, Project Description: We're seeking an IT...

Project Description: We're seeking an IT candidate with experience to help us optimizely,  Skills required: .NET, C# Programming, ASP, eCommerce, SQL

Web service, What is a Web Service? The Web Services are the business l...

What is a Web Service? The Web Services are the business logic components which provide the functionality via the Internet using standard protocols like HTTP. The Web Servic

Different types of joins, What are the different types of joins? 1) IN...

What are the different types of joins? 1) INNER JOIN: The Inner join shows matches only when they exist in both the tables.For example, in the SQL below there are two tabl

Develop a scrapebox software, Develop a scrapebox software Project Descr...

Develop a scrapebox software Project Description: I need a software name scrapebox Skills required are .NET, C Programming, Java, C# Programming, Software Architecture

Newly designed apk file for xbmc on an android tv box, Newly designed APK f...

Newly designed APK file for XBMC on an Android TV Box Project Description: We are seeking someone to have knowledge in Android's operating platform. We are a business that ma

Basic use of "dataview", What is basic use of "DataView"? The "DataView...

What is basic use of "DataView"? The "DataView" represents the whole table or can be small parts of rows depending on some criteria. It is the best used for sorting and finding

Abstract classes, What are abstract classes? The features of the abstra...

What are abstract classes? The features of the abstract class are as follows:- 1.     You can not create an object of the abstract class. 2.     The Abstract class is des

I need a pos like openbravo, I need a POS like openbravo Project Descrip...

I need a POS like openbravo Project Description: i want a POS like openbravo in .net with sql azure and c#. Must be designed also for touch screen.  Web platform Also m

Tfs - spirateam synchronization plugin, TFS - SpiraTeam synchronization plu...

TFS - SpiraTeam synchronization plugin. Project Description: We would like you to develop the subsequent requirements in one plug-in already in production. The plug-in was de

Aana

2/12/2013 12:00:41 AM

You might check out this, this is useful for you

Program:

using System;  

class SumOfNumbers

{

public static void Main()

{

int num,rem,i,counter=0,temp,sum=0;

// num : Contains the actual number inputted via the console

// rem : remainder of the number ''num'' when divided by 10

// i : loop variable

// counter : determines the no. of digits in the inputted number ''num''

// temp : temporary variable used to save the value of ''num'' (Explained further)

Console.Write("Enter an integer number (Not more than 9 digits) : ");

num = int.Parse(Console.ReadLine());    

temp = num;

// Here we are saving ''num'' in ''temp'' coz its value after determining the no. of digits will loose.

// So after its work is done, ''num'' will contain value = 0

// The value of ''num'' is resetted to its original value later from ''temp'' variable

//  determine the no. of digits in the inputted number

while(num > 0)

{

rem = num % 10;

num = num / 10;

if (num <= 0) 

{

break;

}

else

{

counter = counter + 1;

}

}    

Console.WriteLine("Number of digits are = " + (counter+1));  

rem = 0;

// resetting the value of remainder ''rem''  

num = temp;

// resetting the lost value of ''num'' from ''temp''

// determine the reversed of inputted digits

// Funda :

// 1) Divide the number by 10 & determine the remainder. (Save the remainder in ''rem'') 

// This will give us the last digit in the actual inputted number. (Same as reversing numbers logic)

// 2) Add the number so obtained into the variable ''sum''

// 3) Divide the same number by 10 & get the quotient this time. 

// Since division is between the integers, we will get the new number, deprived of the last digit.

// Then again goto step 1) & continue until & unless the counter is equal to ''i'' (coz thats the loop varibale)  

for(i = 0; i<=counter; i++)

{

rem = num % 10;

sum = sum + rem;

num = num / 10;   

}

Console.WriteLine("Sum = " +sum);

Console.ReadLine();  

}

}

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd