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.'%')

Answers were Sorted based on User's Feedback



if a five digit number is input through the keyboard, write a program to calculate the sum of its d..

Answer / synner

#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 ?    11 Yes 20 No

if a five digit number is input through the keyboard, write a program to calculate the sum of its d..

Answer / aha na

#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 30 No

if a five digit number is input through the keyboard, write a program to calculate the sum of its d..

Answer / jegadeesh

#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 ?    11 Yes 36 No

Post New Answer

More C Interview Questions

Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?

0 Answers  


How is a null pointer different from a dangling pointer?

0 Answers  


whats the use of header file in c?

2 Answers  


Does c have an equivalent to pascals with statement?

0 Answers  


main() { int i = 1; int num[] = {1,2,3,4}; num[i] = i++; printf("%d", num[i]); } what will be the output? }

22 Answers   NDS, TCS,


How many parameters should a function have?

0 Answers  


what is the difference b/w NULL and null?

3 Answers   HSBC, IBM,


What is extern storage class in c?

0 Answers  


Write a program that takes a 5 digit number and calculates 2 power that number and prints it

5 Answers   ABS, Accenture, HCL, Infosys, Infotech, SoftSolve, Software India, TCS, Vertex, Vimukti Technologies,


When can a far pointer be used?

0 Answers  


write a fuction for accepting and replacing lowercase letter to'Z' with out using inline function.

5 Answers   Temenos,


without using arithmatic operator convert an intger variable x into x+1

3 Answers  


Categories