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 (2266)
 C++ interview questions  C++ Interview Questions (1121)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (652)
Question
Program to find the sum of digits of a given number until 
the sum becomes a single digit
 Question Submitted By :: C
I also faced this Question!!     Answer Posted By  
 
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 ?    133 Yes 48 No
Ashutosh Shashi
 
Answer
# 2
#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 ?    52 Yes 25 No
Suvabrata Das
 
 
 
Answer
# 3
//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 ?    7 Yes 3 No
T. Ashok Kumar
 
Answer
# 4
#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 ?    12 Yes 9 No
Sanjay M
 
Answer
# 5
#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 ?    6 Yes 4 No
Somasundaram
 
Answer
# 6
82
25
52
63
65
 
Is This Answer Correct ?    0 Yes 9 No
Shreshtha Bhattacharya
 
Answer
# 7
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 ?    28 Yes 40 No
Sohini Khan
 
Answer
# 8
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 ?    45 Yes 70 No
Rama Krishna Sidhartha
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
how to copy a string without using c function   5
Write a program to compute the following 1!+2!+...n!   4
could u able to tell about suresoft technical session   1
How do you write a program which produces its own source code as its output?   4
write an algorithm and c program to add two 2x2 matrics   1
What is volatile in c language? HCL 2
write a program for size of a data type without using sizeof() operator? IBM 22
How do i store a paragraph into a string? for example, if i input a long paragraph, the program will read the words one by one and concatenate them until no word is left.   1
what about "char *(*(*a[])())();" Oracle 3
what is diference between return 0 and return NULL??   3
How can I increase the allowable number of simultaneously open files? CSC 1
Difference between null pointer and dangling pointer? Wipro 7
 
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