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
What is define c?
What are void pointers in c?
What are the 5 elements of structure?
What is the difference between local variable and global variable in c?
What is an array? What the different types of arrays in c?
Explain the difference between null pointer and void pointer.
What are header files in c?
In a switch statement, what will happen if a break statement is omitted?
Explain how can you restore a redirected standard stream?
What does sizeof int return?
I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...
What is data types?
What are different storage class specifiers in c?
Can we initialize extern variable in c?
Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Assume that there are not more than 450 students in the college. 1.write a function to print names of all students who joined in a particular year 2.write a function to print the data of a student whose roll number is given