how to find sum of digits in C?

Answer Posted / d. prashant

#include<stdio.h>
#include<conio.h>
main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
printf("sum = %d",sum);
}

Is This Answer Correct ?    7 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how many errors in c explain deply

1627


Explain how do I determine whether a character is numeric, alphabetic, and so on?

648


How can variables be characterized?

1645


Do string constants represent numerical values?

916


How can I access an I o board directly?

621






What is the difference between pure virtual function and virtual function?

646


how to construct a simulator keeping the logical boolean gates in c

1722


What are comments and how do you insert it in a C program?

737


What is variable declaration and definition in c?

499


What is operator promotion?

625


How can you increase the size of a statically allocated array?

608


List some applications of c programming language?

549


What is malloc return c?

597


plz let me know how to become a telecom protocol tester. thank you.

1740


An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above

703