how to find sum of digits in C?

Answer Posted / pooja

main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
n=n/10;
sum=sum+r;
}
printf("\nsum of digits is %d",sum);
}

Is This Answer Correct ?    57 Yes 11 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the features of c languages?

691


can anyone please tell about the nested interrupts?

1744


please explain every phase in the "SDLC" in the dotnet.

2249


Explain how many levels deep can include files be nested?

688


What is the difference between int main and void main in c?

662






Can a local variable be volatile in c?

641


What is the purpose of sprintf?

687


How can you call a function, given its name as a string?

768


What is far pointer in c?

882


Is javascript based on c?

660


how do you execute a c program in unix.

705


What is the advantage of an array over individual variables?

812


Write a program to swap two numbers without using a temporary variable?

683


Define Spanning-Tree Protocol (STP)

729


A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none

806