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
Explain heap and queue.
What is variables in c?
Do pointers store the address of value or the actual value of a variable?
What are the 32 keywords in c?
Why cant I open a file by its explicit path?
How many levels of indirection in pointers can you have in a single declaration?
Is c easier than java?
How to compare array with pointer in c?
Can the “if” function be used in comparing strings?
Which is better malloc or calloc?
what is the structure pointer?
Write a program to print all permutations of a given string.
What is local and global variable in c?
Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
Why do some versions of toupper act strangely if given an upper-case letter?