Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
 Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM

 Categories  >>  Software  >>  Programming Languages  >>  C

 C Interview Questions C++ Interview Questions VC++ Interview Questions Delphi Interview Questions Programming Languages AllOther Interview Questions
Question
```Program to find the sum of digits of a given number until
the sum becomes a single digit```
Question Submitted By :: Kishore.glitz
I also faced this Question!!     Rank Answer Posted By

Re: Program to find the sum of digits of a given number until the sum becomes a single digit
# 1
int n = 123456789; //any numer of you want sum
int sum = 0;
while (n > 0)
{
int p = n % 10;
sum = sum + p;
n = n / 10;
if(n==0 && sum>9)
{
n=sum;
sum=0;
}
}
printf("%d",sum);

 Is This Answer Correct ? 109 Yes 41 No
Ashutosh Shashi

Re: Program to find the sum of digits of a given number until the sum becomes a single digit
# 2
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 ? 39 Yes 63 No
Rama Krishna Sidhartha

Re: Program to find the sum of digits of a given number until the sum becomes a single digit
# 3
main()
{int n,p,s=0;
while(n>0)
{
p=n%10;
s=s+p;
n=n/10;
}
printf("%d",s);
getch(),
}

 Is This Answer Correct ? 24 Yes 39 No
Sohini Khan

Re: Program to find the sum of digits of a given number until the sum becomes a single digit
# 4
#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 ? 45 Yes 21 No
Suvabrata Das

Re: Program to find the sum of digits of a given number until the sum becomes a single digit
# 5
#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 ? 10 Yes 6 No
Sanjay M

Re: Program to find the sum of digits of a given number until the sum becomes a single digit
# 6
#include<stdio.h>
#include<conio.h>
void main()
{
unsigned int no;
clrscr();

printf("Enter number : ");
scanf("%d", &no);

if(no==0)
printf("sum = 0");
else
{
no=no%9;
if(no==0)
printf("sum = 9");
else
printf("sum = %d", no);
}

getch();
}

 Is This Answer Correct ? 2 Yes 2 No
Somasundaram

Re: Program to find the sum of digits of a given number until the sum becomes a single digit
# 7
//Sum of digits of a number.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,r,m;
int s=0;
cout<<"Sum of digits of a number:-\n";
cout<<"Enter the number: ";
cin>>n;
m=n;
repeat:
while (n>0)
{
r=n%10;
s=s+r;
n=n/10;
}
if(s>9)
{
n=s;
s=0;
goto repeat;
}
cout<<"Sum of digits of the number "<<m<<" is "<<s;
getch();
}

 Is This Answer Correct ? 5 Yes 2 No
T. Ashok Kumar

Re: Program to find the sum of digits of a given number until the sum becomes a single digit
# 8
82
25
52
63
65

 Is This Answer Correct ? 0 Yes 5 No
Shreshtha Bhattacharya

  Question Asked @ Answers Other C Interview Questions difference between function & structure Verizon 7 Which of the following are valid "include" formats? A)#include and #include[file.h] B)#include (file.h) and #include C)#include [file.h] and #include "file.h" D)#include and #include "file.h" Accenture 15 dynamically allocate memory for linear array of n integers,store some elements in it and find some of them 1 What is the output of following program ? int main() { int x = 5; printf("%d %d %d\n", x, x << 2, x >> 2); } Qualcomm 4 in a town the percentage of men is 52 the percentage of total literacy is 48 if total percentage of literate men is 35 of the total population write a program to find the total no of the literate men and women if the population of the town is 80000 1 Q.11 Generate the following pattern using code in any language(c/c++/java) for n no. of rows 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 2 #ifdef TRUE int I=0; #endif main() { int j=0; printf("%d %d\n",i,j); } ADITI 3 if a person is buying coconuts of Rs10,and then sell that coconuts of Rs9,with the loss of one rupee.After that the person became a millaniore.how? Wipro 8 what will be the output of this program? void main() { int a[]={5,10,15}; int i=0,num; num=a[++i] + ++i +(++i); printf("%d",num); } MICROSOFT 2 what is the output of the following code? main() { int I; I=0x10+010+10; printf("x=%x",I); } give detailed reason 3 How to swap two values using a single variable ? condition: Not to use Array and Pointer ? 6 what is computer engg 1 For more C Interview Questions Click Here