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

Write a program to identify if a given binary tree is balanced or not.

785


Explain threaded binary trees?

775


pgm to find any error in linklist(in single linklist check whether any node points any of previous nodes instead of next node)

2286


a construct the"else" part of "if" statement contains anoth "if else" statement is called a) if-else b) else-if-else c) if-else-if-else d) chain if/if-else-if

787


hi send me sample aptitude papers of cts?

1737






When should I declare a function?

725


a value that does not change during program execution a) variabe b) argument c) parameter d) none

809


What is the function of multilevel pointer in c?

759


What is a nested loop?

750


Is array a primitive data type in c?

663


Compare and contrast compilers from interpreters.

783


Should I learn c before c++?

801


What do the functions atoi(), itoa() and gcvt() do?

814


What is #define size in c?

751


What are pointers? What are different types of pointers?

723