Program to find the sum of digits of a given number until
the sum becomes a single digit
Answer Posted / sanjay m
#include<stdio.h>
#include<conio.h>
void main()
{
unsigned int n,c=0,r,i,S=0;
clrscr();
printf("enter no.");
scanf("%d",&n);
while(n>0)
{
{
r=n%10;
c=c+r;
n=n/10;
}
if(c>9)
{
int X=c%10;
int Y=c/10;
S=X+Y;
}
}
if(c<10)
printf("%d",c);
else
printf("%d",S);
getch();
}
| Is This Answer Correct ? | 13 Yes | 14 No |
Post New Answer View All Answers
What is a global variable in c?
What are qualifiers in c?
Can math operations be performed on a void pointer?
What is the purpose of main( ) in c language?
Difference between exit() and _exit() function?
What are multidimensional arrays?
Why cant I open a file by its explicit path?
How can you draw circles in C?
What is meant by type specifiers?
Are the variables argc and argv are always local to main?
How will you declare an array of three function pointers where each function receives two ints and returns a float?
What is the use of parallelize in spark?
How can I do graphics in c?
Why is it important to memset a variable, immediately after allocating memory to it ?
What is the difference between struct and typedef struct in c?