Program to find the sum of digits of a given number until
the sum becomes a single digit
Answer Posted / rama krishna sidhartha
int n = 1234; //any numer of you want sum
int sum = 0;
void main()
{
clrscr();
while (n > 0)
{
int p = n % 10;
sum = sum + p;
n = n / 10;
}
printf("%d",sum);
getch();
}
| Is This Answer Correct ? | 49 Yes | 75 No |
Post New Answer View All Answers
What is the meaning of 2d in c?
Explain what are the advantages and disadvantages of a heap?
find the output? void r(int a[],int c, int n) { if(c>n) { a[c]=a[c]+c; r(a,++c,n); r(a,++c,n); } } int main() { int i,a[5]={0}; r(a,0,5); for(i=0;i<5;i++) printf("\n %d",a[i]); getch(); }
ATM machine and railway reservation class/object diagram
Is there sort function in c?
What is the time and space complexities of merge sort and when is it preferred over quick sort?
What are the basic data types associated with c?
What is structure and union in c?
What is the scope of global variable in c?
In a switch statement, what will happen if a break statement is omitted?
What is the process of writing the null pointer?
What is the use of pointers in C?
Explain how can a program be made to print the line number where an error occurs?
What is meant by initialization and how we initialize a variable?
Why should I prototype a function?