Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is derived datatype in c?

1145


What is the use of linkage in c language?

1102


What are the advantages of c preprocessor?

1316


pgm to find number of words starting with capital letters in a file(additional memory usage not allowed)(if a word starting with capital also next letter in word is capital cann't be counted twice)

2387


Explain what header files do I need in order to define the standard library functions I use?

1229


What are the features of c languages?

1140


What is array of structure in c?

1254


What are the different types of control structures in programming?

1178


Can the “if” function be used in comparing strings?

1108


Can we change the value of #define in c?

1056


What is f'n in math?

1142


What are integer variable, floating-point variable and character variable?

1299


pierrot's divisor program using c or c++ code

2286


I heard that you have to include stdio.h before calling printf. Why?

1115


What is the use of clrscr?

1156