if a five digit number is input through the keyboard, write
a program to calculate the sum of its digits.
(hint:-use the modulus operator.'%')
Answer Posted / ruchi
#include<stdio.h>
#include<conio.h>
int main()
{
int n,m,m1,s=0,d,sum;
printf("\nEnter the number ");
scanf("%d",&n);
m=n%10;
d=n/10;
while(d>=10)
{
m1=d%10;
d=d/10;
s =s+m1;
}
sum=s+m+d;
printf("\nSum is %d",sum);
getch();
}
| Is This Answer Correct ? | 13 Yes | 17 No |
Post New Answer View All Answers
What is a wrapper function in c?
What is class and object in c?
What is keyword with example?
What is volatile variable how do you declare it?
What are dangling pointers in c?
What is the process of writing the null pointer?
#include main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf(" %d",*p); *p = 10; printf(" %d %d",i,*p); c = (int*) calloc(2); printf(" %d ",*c); }
What is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
In c programming language, how many parameters can be passed to a function ?
Explain what is page thrashing?
How pointer is different from array?
Is malloc memset faster than calloc?
Why enum is used in c?
How can I run c program?
What is #include stdio h?