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 (2262)
 C++ interview questions  C++ Interview Questions (1118)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (646)
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 :: C
I also faced this Question!!     Answer Posted By  
 
Answer
# 1
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 ?    81 Yes 24 No
Sriharsha
 
Answer
# 2
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 ?    120 Yes 75 No
K.kavitha
 
 
 
Answer
# 3
#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 ?    57 Yes 24 No
Rashmi Sharma
 
Answer
# 4
#include<stdio.h>
int main()
{
int n,d1,d2,d3,d4,d5,s;
printf("enter a five digit no");
scanf("%d",&n);
d5=n%10;n=n/10;
d4=n%10;n=n/10;
d3=n%10;n=n/10;
d2=n%10;n=n/10;
d1=n%10;
s=d1+d2+d3+d4+d5;
return 0;
}
 
Is This Answer Correct ?    12 Yes 3 No
Jyoti
 
Answer
# 5
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 11 No
Richa
 
Answer
# 6
Try it. It will seriously work. You would appreciate it.

#include<stdio.h>
#include<conio.h>

int main()

{
int x;
int a;
int b;
int c;
int d;
int e;
int sum;

printf("Please enter a five digit number:\n");
scanf("%d",&x);

a=x%10;
b=(x/10)% 10;
c=(x/100)% 10;
d=(x/1000)%10;
e=(x/10000)%10;

sum=a+b+c+d+e;

printf("\n\nThe sum of all digits is %d.",sum);

getch();
return 0;

}
 
Is This Answer Correct ?    5 Yes 0 No
Haris
 
Answer
# 7
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,d,e;
int digit,number,sum;

printf("\n\n\n");

printf("Enter a five-digit number :");
scanf("%d",&number);

digit=number%10;
a=digit;

number=number/10;
digit=number%10;
b=digit;

number=number/10;
digit=number%10;
c=digit;

number=number/10;
digit=number%10;
d=digit;

number=number/10;
digit=number%10;
e=digit;

sum=a+b+c+d+e;
printf("\nThe sum of five-digit number is : %d",sum);

getch();
}
 
Is This Answer Correct ?    3 Yes 0 No
Areeb Ahmed Khan
 
Answer
# 8
#include<stdio.h>

main ()
{
int num, a, b,c,d,e, sum;

printf ("Enter the five digit number : ");
scanf ("%d", &num);
e = num % 10;
d = (num / 10)% 10;
c = (num / 100)% 10;
b = (num / 1000)% 10;
a = (num / 10000)% 10;
sum= a+b+c+d+e;
printf ("The sum of the digits is: %d", sum);

}
 
Is This Answer Correct ?    3 Yes 0 No
Joy
 
Answer
# 9
#include<stdio.h>
void main()
{
int i,j;
scanf("%d",&i);
if(i>9)
{
if((i%9)==0)
printf("The sum of digit is 9");
else
{
j=i%9;
printf("%d",j);
}
}
else
{
printf("The sum of digit is ",i);
}

}

//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 answer u are looking...
 
Is This Answer Correct ?    4 Yes 2 No
Jegadeesh
 
Answer
# 10
#include"stdio.h"
main ()
{
int number, last_digit, next_digit, total;
printf ("Enter the number whose sum of digits is to be calculated: ");
scanf ("%d", &number);
last_digit = number%10;
total = last_digit;
next_digit = (number/10) % 10;
total = total + next_digit;
next_digit = (number/100) % 10;
total = total + next_digit;
next_digit = (number/1000) %10;
total = total + next_digit;
next_digit = (number/10000) %10;
total = total + next_digit;
printf ("The sum of the digits of the entered number is: %d", total);
}
 
Is This Answer Correct ?    2 Yes 0 No
Thamizharasan
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
1)which of following operator can't be overloaded. a)== b)++ c)?! d)<= Siemens 16
what is a function prototype?   1
i have a written test in tomorrow Value-Labs 1
How can I make a program in c to print 'Hello' without using semicolon in the code? C-DAC 9
why we are using semicolon at the end of printh statment HCL 2
how to make c program without a libary? e.g.#include<stdio.h> libary is not in c progaram.   2
How can I read a directory in a c program? CSC 1
wats the diference btwen constant pointer and pointer to a constant.pls give examples.   9
ABCDCBA ABC CBA AB BA A A TCS 4
Write a program in C to reverse a number by recursive function?   1
what is the differance between pass by reference and pass by value. Infosys 6
program for following output using for loop? 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 Aptech 8
 
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