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 keywords are there in c?

591


Are negative numbers true in c?

600


Explain about the functions strcat() and strcmp()?

598


Here is a good puzzle: how do you write a program which produces its own source code as output?

599


#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }

783






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

698


Which of the following operators is incorrect and why? ( >=, <=, <>, ==)

668


what will be the output for the following main() { printf("hi" "hello"); }

9332


What are identifiers in c?

633


Explain the meaning of keyword 'extern' in a function declaration.

726


what is recursion in C

616


Who invented b language?

916


what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above

678


What do you understand by friend-functions? How are they used?

647


FILE PROGRAMMING

1779