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

Answers were Sorted based on User's Feedback



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

Answer / ashutosh shashi

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 ?    157 Yes 63 No

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

Answer / 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

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

Answer / t. ashok kumar

//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 ?    14 Yes 6 No

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

Answer / somasundaram

#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 ?    9 Yes 5 No

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

Answer / 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

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

Answer / shreshtha bhattacharya

82
25
52
63
65

Is This Answer Correct ?    1 Yes 13 No

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

Answer / sohini khan

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 ?    29 Yes 43 No

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

Answer / rama krishna sidhartha

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 ?    49 Yes 75 No

Post New Answer

More C Interview Questions

how to find that no is int or float?

5 Answers  


How do you define structure?

0 Answers  


write a program which counts a product of array elements lower than 10.

1 Answers  


What is the difference between procedural and functional programming?

0 Answers  


Which of the following operators is incorrect and why? ( >=, <=, <>, ==)

0 Answers  






What do you mean by team??

5 Answers   Student,


main() {int i=5; // line 1 i=(++i)/(i++); // line 2 printf("%d",i); // line 3 } output is 2 but if we replace line 2 and line 3 by printf("%d",i=(++i)/(i++)); then output is 1. Why?

1 Answers   GATE,


how could explain about job profile

0 Answers  


Write a program to maintain student’s record. Record should not be available to any unauthorized user. There are three (3) categories of users. Each user has its own type. It depends upon user’s type that which kind of operations user can perform. Their types and options are mentioned below: 1. Admin (Search Record [by Reg. No or Name], View All Records, Insert New Record, Modify Existing Record) 2. Super Admin (Search Record [by Reg. No or Name], View All Records, Insert New Record, Modify Existing Record, Delete Single Record) 3. Guest (Search Record [by Reg. No or Name], View All Records) When first time program runs, it asks to create accounts. Each user type has only 1 account (which means that there can be maximum 3 accounts). In account creation, following options are required: Login Name: <6-10 alphabets long, should be unique> Password: <6-10 alphabets long, should not display characters when user type> Confirm Password: <must match with the Password, should not display characters when user type> Account Type: <One character long, A or S or G where A for Admin, S for Super Admin, G for Guest> Login Name, Password and Account Type should be stored in a separate file in encrypted form. (Encryption means that actual information should be changed and Decryption means that Encrypted information is changed back to the actual information) If any of the above mentioned requirement(s) does not meet then point out mistake and ask user to specify information again. When Program is launched with already created accounts, it will ask for user name and password to authenticate. On successful authentication, give options according to the user’s type.

0 Answers  


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

1 Answers  


Is main is user defined function?

0 Answers  


What is floating point exception error? And what are different types of errors occur during compile time and run time? why they occur?

1 Answers  


Categories