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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why c is called procedure oriented language?

1061


is it possible to create your own header files?

1108


int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;

1837


Why is c called a mid-level programming language?

1213


How can I do graphics in c?

1040


Is c call by value?

1026


What is the advantage of a random access file?

1208


How can I change their mode to binary?

1129


What is a program?

1276


Why doesnt this code work?

1074


What is c language used for?

992


Explain what is the difference between far and near ?

1116


What is c basic?

1186


Tell me the use of bit field in c language?

1074


What is the ANSI C Standard?

1286