Answer Posted / keerthireddy
#include<stdio.h>
#include<conio.h>
main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n>0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
printf("sum = %d",sum);
}
output:
3456
how it works as follows:
3456%10 means it gives reminder as 6
6 will be added to the sum
3456/10 means it gives quotient as 345
then again loop is executing until the n value is 0
finally the result as 6+5+4+3=18
| Is This Answer Correct ? | 9 Yes | 1 No |
Post New Answer View All Answers
How can you convert integers to binary or hexadecimal?
Can a variable be both const and volatile?
What is time complexity c?
How do I use void main?
What is a struct c#?
What is static identifier?
Why isn't it being handled properly?
Tell me about low level programming languages.
Should a function contain a return statement if it does not return a value?
Write a program to check whether a number is prime or not using c?
Is c++ based on c?
What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?
.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }
Explain what could possibly be the problem if a valid function name such as tolower() is being reported by the c compiler as undefined?
What is the explanation for cyclic nature of data types in c?