how to find sum of digits in C?

Answer Posted / giri

#include <stdio.h>
#include <conio.h>

void main()
{
int sum=0, num, mul=1;
printf("Enter the number");
scanf("%d", &num);

while(num)
{
sum = sum + ((num%10)*mul);
num = num/10;
mul = mul * 10;
}

printf("Sum is %d", sum);
}

Is This Answer Correct ?    6 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you mean by Recursion Function?

632


What is the difference between ++a and a++?

695


What are Macros? What are its advantages and disadvantages?

649


What is structure padding in c?

628


Why is c called a mid-level programming language?

729






Explain how do you determine a file’s attributes?

594


What is use of integral promotions in c?

666


How can I delete a file?

630


Can stdout be forced to print somewhere other than the screen?

627


Write a program to generate a pulse width frequency of your choise,which can be variable by using the digital port of your processor

2984


Linked lists -- can you tell me how to check whether a linked list is circular?

646


What does the error message "DGROUP exceeds 64K" mean?

727


Is python a c language?

552


When can a far pointer be used?

588


Write a code to determine the total number of stops an elevator would take to serve N number of people.

729