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

What does the characters “r” and “w” mean when writing programs that will make use of files?

1487


Why we use conio h in c?

1245


What Is The Difference Between Null And Void Pointer?

1271


int far *near * p; means

3563


What are the characteristics of arrays in c?

1056


Explain the use of 'auto' keyword

1125


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

3697


Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.

1119


Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

1043


Why clrscr is used after variable declaration?

1703


What are the advantages of Macro over function?

2034


What is the acronym for ansi?

1052


all c language question

2449


How to throw some light on the b tree?

1092


hi send me sample aptitude papers of cts?

2171