how to find sum of digits in C?

Answer Posted / vani

//sum of digits in c//
#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,sum=0;
clrscr();
printf("\n enter the number:");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
printf("sum=%d");
getch();
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the purpose of the statement: strcat (S2, S1)?

644


Describe newline escape sequence with a sample program?

660


Why pointers are used?

633


What is the difference between the = symbol and == symbol?

631


What is modeling?

651






I need a sort of an approximate strcmp routine?

664


Is malloc memset faster than calloc?

622


What is the size of structure in c?

705


In C language, a variable name cannot contain?

747


Explain function?

667


a program that performs some preliminary processing in C, it acts upon certain directives that will affect how the compiler does its work a) compiler b) loader c) directive d) preprocessor

645


Do variables need to be initialized?

623


If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?

782


What should malloc() do?

651


Explain 'far' and 'near' pointers in c.

710