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 is c known as a mother language?

1189


What are categories used for in c?

1036


What are the types of bitwise operator?

1050


When can you use a pointer with a function?

995


what is reason of your company position's in india no. 1.

2237


Is null always equal to 0(zero)?

993


Define C in your own Language.

1035


Why do we use null pointer?

999


Can you add pointers together? Why would you?

1076


How does #define work?

1014


how to find anagram without using string functions using only loops in c programming

3136


How can you pass an array to a function by value?

1059


Explain what is a stream?

1034


What are called c variables?

1015


What would happen to X in this expression: X += 15; (assuming the value of X is 5)

1884