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
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 |
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 |
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 |
Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?
How is a null pointer different from a dangling pointer?
whats the use of header file in c?
Does c have an equivalent to pascals with statement?
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?
what is the difference b/w NULL and null?
What is extern storage class in c?
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?
write a fuction for accepting and replacing lowercase letter to'Z' with out using inline function.
without using arithmatic operator convert an intger variable x into x+1