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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what happens if you free a pointer twice?

578


Add Two Numbers Without Using the Addition Operator

326


Tell me with an example the self-referential structure?

540


What is memory leak in c?

601


How can you allocate arrays or structures bigger than 64K?

654






Explain what is gets() function?

603


What is non linear data structure in c?

546


What is static volatile in c?

544


What is a stream in c programming?

568


What is the heap in c?

615


What is the advantage of using #define to declare a constant?

597


What is function prototype in c with example?

550


There seem to be a few missing operators ..

589


define string ?

638


Using functions, write a program that multiplies two arrays. Use the following functions: - Function ReadArray - Function MultiplyArrays - Function DisplayArrays

1856