how to find sum of digits in C?

Answer Posted / gg

try this....

#include<stdio.h>
int main()
{
int n,m,sum=0;
scanf("%d",&n);
for(m=0;((m=n%10)!=0);n=(n/10))
sum+=m;
printf("count is %d\n",sum);
}

Is This Answer Correct ?    13 Yes 16 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Create a simple code fragment that will swap the values of two variables num1 and num2.

819


How can I recover the file name given an open stream or file descriptor?

600


Hello. How to write a C program to check and display president party like if i type in the console "biden" and hit enter the output shoud be : "biden is democrat" and if i type "trump" and hit enter the output shoud be: "trump is republican"

1584


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

1892


illustrate the use of address operator and dereferencing operator with the help of a program guys plzzz help for this question

1590






i want to switch my career from quailty assurance engineering to development kindly guide me from which programming language its better for me to start plz refer some courses or certifications too i have an experience of 1.5 yrs in QA field.Kindly guide me

1484


A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers

653


Which type of language is c?

656


praagnovation

1783


What does the && operator do in a program code?

700


Differentiate between static and dynamic modeling.

626


What is the function of volatile in c language?

670


What is the purpose of type declarations?

683


What is the maximum length of an identifier?

667


What is NULL pointer?

680