Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

how to find sum of digits in C?

Answer Posted / keerthireddy

#include<stdio.h>
#include<conio.h>
main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n>0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
printf("sum = %d",sum);
}
output:
3456
how it works as follows:
3456%10 means it gives reminder as 6
6 will be added to the sum
3456/10 means it gives quotient as 345
then again loop is executing until the n value is 0
finally the result as 6+5+4+3=18

Is This Answer Correct ?    9 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what is the benefit of using enum to declare a constant?

1019


What is the difference between declaring a variable and defining a variable?

1183


Function calling procedures? and their differences? Why should one go for Call by Reference?

1040


Can an array be an Ivalue?

1052


How to throw some light on the b tree?

1019


Why is this loop always executing once?

998


What does c value mean?

1112


Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?

1047


What is integer constants?

1014


What is optimization in c?

946


what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)

2341


Is stack a keyword in c?

1037


Explain the red-black trees?

1049


How many types of arrays are there in c?

995


Describe static function with its usage?

1151