Program to find the sum of digits of a given number until
the sum becomes a single digit

Answer Posted / suvabrata das

#include<stdio.h>
#include<conio.h>
void main()
{
int n,c=0,r,i;
clrscr();
printf("enter no.");
scanf("%d",&n);
while(n>0)
{
{
r=n%10;
c=c+r;
n=n/10;
}
if(c>9)
{
n=c;
c=0;
}
}
printf("%d",c);
getch();
}

Is This Answer Correct ?    58 Yes 34 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Tell me what is null pointer in c?

611


An application package has been provided to you without any documents for the following application. The application needs to be tested. How will you proceed?

665


Why clrscr is used after variable declaration?

1035


Why is structure important for a child?

601


Do you know the difference between exit() and _exit() function in c?

605






Can a variable be both static and volatile in c?

604


What are high level languages like C and FORTRAN also known as?

680


In c programming language, how many parameters can be passed to a function ?

626


general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only

584


What is substring in c?

634


What are the difference between a free-standing and a hosted environment?

737


What is function and its example?

621


Why #include is used in c language?

592


How can I find the modification date of a file?

698


What is extern storage class in c?

509