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
if a five digit number is input through the keyboard, write
a program to calculate the sum of its digits.
(hint:-use the modulus operator.'%')
 Question Submitted By :: Madhu
I also faced this Question!!     Rank Answer Posted By  
 
  Re: if a five digit number is input through the keyboard, write a program to calculate the sum of its digits. (hint:-use the modulus operator.'%')
Answer
# 1
main()
{
int num=0,sum=0,k=0;
pirntf("enter the number\n");
scanf("%d",num);
while(num!=0);
{
k=num%10;
sum=sum+k;
num=num/10;
}
printf("%d",sum);
}
 
Is This Answer Correct ?    116 Yes 73 No
K.kavitha
 
  Re: if a five digit number is input through the keyboard, write a program to calculate the sum of its digits. (hint:-use the modulus operator.'%')
Answer
# 2
void main()
{
long int num;
int sum=0,temp;
clrscr();
printf("Enter the numbe\n");
scanf("%ld",&num);
while(num!=0)
{
temp=num%10;
sum=sum+temp;
num=num/10;
}
printf("%d",sum);
getch();
}

 
Is This Answer Correct ?    76 Yes 24 No
Sriharsha
 
 
 
  Re: if a five digit number is input through the keyboard, write a program to calculate the sum of its digits. (hint:-use the modulus operator.'%')
Answer
# 3
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
scanf("%d",&i);
if((i%9)==0)
printf("The sum of digit is 9");
else
{
j=i%9;
printf("%d",j);
}
}
 
Is This Answer Correct ?    28 Yes 32 No
Jegadeesh
 
  Re: if a five digit number is input through the keyboard, write a program to calculate the sum of its digits. (hint:-use the modulus operator.'%')
Answer
# 4
#include<stdio.h>
void main()
{
int i,j;
scanf("%d",&i);
if((i%9)==0)
printf("The sum of digit is 9");
else
{
j=i%9;
printf("%d",j);
}
}

//the above will print result as 6 if given as 12345 since
1+2+3+4+5=15 and proceeding 1+5 we get as 6.....
is this an apt answer...
 
Is This Answer Correct ?    9 Yes 35 No
Jegadeesh
 
  Re: if a five digit number is input through the keyboard, write a program to calculate the sum of its digits. (hint:-use the modulus operator.'%')
Answer
# 5
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,sum=0;
clrscr();
printf("\n enter a number",i);
scanf("%d",&i);

while(i<=0)
{
j=i%10;
sum=sum+j;
i=i/10;
}
printf("\n the sum of the digits
are:%d\n");
getch();
}
 
Is This Answer Correct ?    14 Yes 29 No
Aha Na
 
  Re: if a five digit number is input through the keyboard, write a program to calculate the sum of its digits. (hint:-use the modulus operator.'%')
Answer
# 6
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
long int num;
int sum=0,temp;
clrscr();
printf("Enter the numbe\n");
scanf("%ld",&num);
while(num!=0)
{
temp=num%10;
sum=sum+temp;
num=num/10;
}
printf("%d",sum);
getch();
}
 
Is This Answer Correct ?    10 Yes 17 No
Synner
 
  Re: if a five digit number is input through the keyboard, write a program to calculate the sum of its digits. (hint:-use the modulus operator.'%')
Answer
# 7
#include<sthio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,f,g,h,i,j,k,l;
printf("enter a five digit number");
scanf("%d",&a);
b=a%10;
c=a/10;
d=c%10;
e=c/10;
f=e%10;
g=e/10;
h=g%10;
i=g/10;
j=i%10;
k=i/10;
l=b+d+f+h+j;
printf("sum of the digit=%d",l);
getch();
}
 
Is This Answer Correct ?    54 Yes 23 No
Rashmi Sharma
 
  Re: if a five digit number is input through the keyboard, write a program to calculate the sum of its digits. (hint:-use the modulus operator.'%')
Answer
# 8
#include<stdio.h>
#include<conio.h>
int main()
{
int n,m,m1,s=0,d,sum;
printf("\nEnter the number ");
scanf("%d",&n);
m=n%10;
d=n/10;
while(d>=10)
{
m1=d%10;
d=d/10;
s =s+m1;
}
sum=s+m+d;
printf("\nSum is %d",sum);
getch();
}
 
Is This Answer Correct ?    12 Yes 14 No
Ruchi
 
  Re: if a five digit number is input through the keyboard, write a program to calculate the sum of its digits. (hint:-use the modulus operator.'%')
Answer
# 9
#include<stdio.h>
#include<conio.h>
void main()
{
int num=0,sum=0,k=0;
pirntf("enter the number\n");
scanf("%d",num);
while(num!=0);
{
k=num%10;
sum=sum+k;
num=num/10;
}
printf("%d",sum);
getch();
}
 
Is This Answer Correct ?    12 Yes 12 No
Nishant Rai
 
  Re: if a five digit number is input through the keyboard, write a program to calculate the sum of its digits. (hint:-use the modulus operator.'%')
Answer
# 10
main()
{
int num , sum=0 ;
printf(" enter 5 digit no. " );
scanf(" %d " , num);
while (num!=0)
{ sum+=num%10;
num=num/10;
}
printf("sum is = %d " , sum );
getch();
}
 
Is This Answer Correct ?    17 Yes 10 No
Richa
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
what is the output of the below code? main( ) { printf ( "\nOnly stupids use C?" ) ; display( ) ; } display( ) { printf ( "\nFools too use C!" ) ; main( ) ; }   2
what are two kinds of java   2
How we can set and clear bit in a byte using macro function? L&T 2
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1   3
if function is declared as static in one source file, if I would like to use the same function in some other source file...is it possible....how ? NetApp 2
why in C,C++'s int size is 2 byte and .net(c#) int Size is 4 byte?   2
Write a C program that computes the value ex by using the formula ex =1+x/1!+x2/2!+x3+3!+.   1
how does a general function , that accepts an array as a parameter, "knows" the size of the array ? How should it define it parameters list ? TCS 2
wat is the output int main() { char s1[]="Hello"; char s2[]="Hello"; if(s1==s2) printf("Same"); else printf("Diff"); }   3
WHAT IS RTGS N MINIMUM AMT TO B TRANSFERD N WHAT R THE CHARGES ON MINIMUM AMT N IN WHICH BANK WE CAN DO IT?   1
write a program to find out number of on bits in a number? Huawei 17
Is both getch() and getchar() functions are similar? if it is similar means why these two functions are used for same usage? if it is not similar means what is the difference? Infosys 1
 
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