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

what is computer

4 Answers  


print ur name 20,000 times without using inbuilt library functions like printf,scanf,gets,puts,getchar or putchar

4 Answers   IBM,


18)struct base {int a,b; base(); int virtual function1(); } struct derv1:base{ int b,c,d; derv1() int virtual function1(); } struct derv2 : base {int a,e; } base::base() { a=2;b=3; } derv1::derv1(){ b=5; c=10;d=11;} base::function1() {return(100); } derv1::function1() { return(200); } main() base ba; derv1 d1,d2; printf("%d %d",d1.a,d1.b) o/p is a)a=2;b=3; b)a=3; b=2; c)a=5; b=10; d)none 19) for the above program answer the following q's main() base da; derv1 d1; derv2 d2; printf("%d %d %d",da.function1(),d1.function1(),d2.function1 ()); o/p is a)100,200,200; b)200,100,200; c)200,200,100; d)none 20)struct { int x; int y; }abc; you can not access x by the following 1)abc-->x; 2)abc[0]-->x; abc.x; (abc)-->x; a)1,2,3 b)2&3 c)1&2 d)1,3,4

1 Answers  


Differentiate between a for loop and a while loop? What are it uses?

0 Answers   TISL,


What is the difference between array and pointer?

0 Answers  


What is union and structure?

0 Answers  


What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.

0 Answers  


struct ptr { int a; char b; int *p; }abc; what is d sizeof structure without using "sizeof" operator??

9 Answers   Verifone,


Why is c so powerful?

0 Answers  


Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

0 Answers   Huawei,


get any number as input except 1 and the output will be 1.without using operators,expressions,array,structure.don't print 1 in printf statement

3 Answers  


write a program for the normal snake games find in most of the mobiles.

0 Answers   Accenture, Wipro,


Categories