ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Programming Languages >> C
 
 


 

 
 C interview questions  C Interview Questions (2248)
 C++ interview questions  C++ Interview Questions (1106)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (644)
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
Answer
# 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 ?    113 Yes 43 No
Ashutosh Shashi
 
  Re: Program to find the sum of digits of a given number until the sum becomes a single digit
Answer
# 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 ?    41 Yes 68 No
Rama Krishna Sidhartha
 
 
 
  Re: Program to find the sum of digits of a given number until the sum becomes a single digit
Answer
# 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 ?    25 Yes 39 No
Sohini Khan
 
  Re: Program to find the sum of digits of a given number until the sum becomes a single digit
Answer
# 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 ?    47 Yes 22 No
Suvabrata Das
 
  Re: Program to find the sum of digits of a given number until the sum becomes a single digit
Answer
# 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 8 No
Sanjay M
 
  Re: Program to find the sum of digits of a given number until the sum becomes a single digit
Answer
# 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 ?    4 Yes 3 No
Somasundaram
 
  Re: Program to find the sum of digits of a given number until the sum becomes a single digit
Answer
# 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 3 No
T. Ashok Kumar
 
  Re: Program to find the sum of digits of a given number until the sum becomes a single digit
Answer
# 8
82
25
52
63
65
 
Is This Answer Correct ?    0 Yes 6 No
Shreshtha Bhattacharya
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
How to calculate sum   2
what is the difference between declaration ,defenetion and initialization of a variable? LG-Soft 7
how to use virual function in real time example CTS 1
application of static variables in real time Bosch 1
can u suggest me am in a confusion to choose whether to go to c programming or a software testing . am a graduate in B.sc(electronics).   1
Program to find larger of the two numbers without using if-else,while,for,switch iNautix 11
How can I read a directory in a C program? Wipro 2
write a c programs to do multiplication of two numbers with out using arithmatic operator ?????????? TCS 7
What is the Difference between Macro and ordinary definition? Motorola 3
I have one doubt. What does below statement mean? #define sizeof(operator) where operator can be int or float etc. Does this statement meaningful and where it can be used?   1
What is the difference b/w main() in C language and main() in C++.   7
How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS? Aricent 2
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com