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


Please Help Members By Posting Answers For Below Questions

What are pointers? What are different types of pointers?

634


What is the auto keyword good for?

631


Why do we use int main instead of void main in c?

626


Why c is called a mid level programming language?

607


What are the advantages and disadvantages of pointers?

580






What is pointers in c?

661


When should structures be passed by values or by references?

588


What do you mean by scope of a variable in c?

546


Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.

630


Does c have class?

615


Explain how do you convert strings to numbers in c?

598


How do shell structures work?

572


What is a built-in function in C?

799


What is the explanation for cyclic nature of data types in c?

651


The postoder traversal is 7,14,3,55,22,5,17 Then ur Inorder traversal is??? please help me on this

2940