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 / pavan kumar
#include<stdio.h>
int main()
{
int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,sum;
printf("Enter the five digit number:");
scanf("%d",&sum);
a=sum%10;
b=sum/10;
c=b%10;
d=b/10;
e=d%10;
f=d/10;
g=f%10;
h=f/10;
printf("sum of the digits:%d",a+c+e+g+h);
}
Is This Answer Correct ? | 7 Yes | 4 No |
Answer / amit amar mahesh bhava
#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 ? | 7 Yes | 5 No |
#include<stdio.h>
#include<conio.h>
void 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);
getch();
}
Is This Answer Correct ? | 13 Yes | 14 No |
Answer / thamizharasan
#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 ? | 3 Yes | 4 No |
Answer / aryan garg
#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;
printf("sum of the digits of number is : %d",s);
return 0;
}
Is This Answer Correct ? | 0 Yes | 2 No |
Answer / jegadeesh
#include<stdio.h>
#include<conio.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);
}
}
Is This Answer Correct ? | 29 Yes | 33 No |
Answer / ruchi
#include<stdio.h>
#include<conio.h>
int main()
{
int n,m,m1,s=0,d,sum;
printf("\nEnter the number ");
scanf("%d",&n);
m=n%10;
d=n/10;
while(d>=10)
{
m1=d%10;
d=d/10;
s =s+m1;
}
sum=s+m+d;
printf("\nSum is %d",sum);
getch();
}
Is This Answer Correct ? | 13 Yes | 17 No |
Answer / revanth kumar.p
include<stdio.h>
#include<conio.h>
int main()
{
int num,len = 1,a,b;
printf("Enter a number");
scanf("%d",&num);
while(num >= 10)
{
num = num/10;
len++;
}
printf("%d",len);
a=len;
a=len*(len+1)%2;
printf("\n%d",a);
b=len;
b=len*(len+1)/2;
printf("\n%d",b);
a=a+b;
printf("\n%d",a);
getch();
}
Is This Answer Correct ? | 4 Yes | 9 No |
Answer / saurabh vyas
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 ? | 4 Yes | 9 No |
Answer / rajrartan singh
#include<stdio.h>
#include<conio.h>
void main();
{
int n,d1,d2,d3,d4,d5,sum;
ptintf("enter the five digit no.");
scanf("d",&n);
s=d1+d2+d3+d4+d5;
getch();
}
Is This Answer Correct ? | 4 Yes | 10 No |
write a program which will count occurance of a day between two dates.
Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.
how can i print "hello"
write a program to find out prime number using sieve case?
Explain the importance and use of each component of this string: Foo.Bar, Version=2.0.205.0, Culture=neutral, PublicKeyToken=593777ae2d274679d
what is computer
What is the difference between array and pointer?
What does s c mean on snapchat?
What are enums in c?
What is meant by 'bit masking'?
How old is c programming language?
What is structure packing in c?