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 / sriharsha
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 ? | 111 Yes | 42 No |
Answer / k.kavitha
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 ? | 137 Yes | 90 No |
Answer / rashmi sharma
#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 ? | 85 Yes | 41 No |
Answer / joy
#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 ? | 25 Yes | 5 No |
Answer / jyoti
#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 ? | 29 Yes | 13 No |
Answer / md osama
#include<stdio.h>
#include<conio.h>
void main()
{
int d1,d2,d3,d4,d5,sum;
long num;
clrscr();
printf("enter the five digit number:");
scanf("%ld",&num);
d1=(num%10);
d2=(num%100-num%10)/10;
d3=(num%1000-num%100)/100;
d4=(num%10000-num%1000)/1000;
d5=(num-num%10000)/10000;
sum=d1+d2+d3+d4+d5;
printf("\n the sum of the digit is:%d",sum);
}
Is This Answer Correct ? | 12 Yes | 1 No |
Answer / richa
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 ? | 24 Yes | 16 No |
Answer / haris
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 ? | 12 Yes | 5 No |
Answer / jegadeesh
#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 ? | 9 Yes | 4 No |
Answer / areeb ahmed khan
#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 ? | 7 Yes | 2 No |
int x=5; printf("%d%d%d",x,x<<2,x>>2);
what is difference between array of characters and string
how to make program without <> in libray.
If a five digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits.For example if the number that is input is 12391 then the output should be displayed as 23402
write a c program to find reminder and quotient if one number is divided by other.to code this program don't use more than 2 variables
How many bytes are occupied by near, far and huge pointers (dos)?
Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.
write a C and C++ programme to implement the A,bubble sort B,quick sort C,insertion sort D,sequential search E,binary search
What is the use of a semicolon (;) at the end of every program statement?
main() { int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }
5 Answers Vector, Vector Solutions,
what is difference between procedural language and functional language ?
c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above