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

I need mt4 programmer, I need mt4 programmer Project Description: I'm...

I need mt4 programmer Project Description: I'm seeking a professional programmer to teach me MQL I have few years experience in manual trading but totally NONE in MT4 / EA

Hardware monitor tool in visual basic, Hardware Monitor Tool in Visual Basi...

Hardware Monitor Tool in Visual Basic Project Description: Hi, seeking a developer who is experienced in Visual Basic 10 Or Visual Basic 13 and will develop an application li

Todo list - finalize application, The purpose of this project is to ?nalize...

The purpose of this project is to ?nalize your TODO application.  For this project we are aiming to achieve the following: Objectives: Integrate a fully functional mobile

Design develop and implement a token web application, This assignment requi...

This assignment requires you to design, develop and implement a token web application. It is intended to assess your mastery of the web application development concepts and ASP.NET

Ways of parsing xml document, What are the ways of parsing XML document? ...

What are the ways of parsing XML document? The XML parser sits in between the XML document and the application who want to use the XML document. The Parser exposes a set of wel

Published or precreated objects in remoting, What is fundamental of publish...

What is fundamental of published or precreated objects in Remoting? In the scenarios of the singleton or single call the objects are created dynamically. But in some situations

Types of compatibility in vb6, What are types of compatibility in VB6 T...

What are types of compatibility in VB6 There are three possible project compatibility settings: No Compatibility Project Compatibility Binary Compatibility

I have a website with a photo gallery, I have a website with a photo galler...

I have a website with a photo gallery using PhotoHandler -photohandler.codeplex.com I require the code added/ modified to display the image file names under the preview or thumbnai

Targin protocol and stock market protocol, Project Description: We need ...

Project Description: We need to construct services in C# or VB.NET that can manipulate with a Targin TIP Protocol Server (protocol for financial information exchange), receive d

Thread.join() in threading, What is Thread.Join() in threading? There a...

What is Thread.Join() in threading? There are 2 versions of Thread.Join :- Thread.join(). Thread.join(Integer) this returns a Boolean value. The Thread.Join

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