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

WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.

2030


Explain the meaning of keyword 'extern' in a function declaration.

729


What is the right type to use for boolean values in c? Is there a standard type? Should I use #defines or enums for the true and false values?

610


What is the difference between volatile and const volatile?

571


Explain what standard functions are available to manipulate strings?

614






.find the output of the following program? char*myfunc(char*ptr) { ptr +=3; return (ptr); } int main() { char*x,*y; x="HELLO"; y=myfunc(x); printf("y = %s ",y); return 0; }

2004


int i=10; printf("%d %d %d", i, i=20, i);

1018


how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?

1500


What is the process of writing the null pointer?

611


How can this be legal c?

656


Why is c faster?

596


What is the benefit of using const for declaring constants?

592


"%u" unsigned integer print the a) address of variable b) value of variable c) name of a variable d) none of the above

617


Can a function argument have default value?

676


Is c dynamically typed?

671