answersLogoWhite

0

C program to add the digits of a given number?

Updated: 8/18/2019
User Avatar

Wiki User

12y ago

Best Answer

#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);

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program to add the digits of a given number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a c program to add the digits of a given no?

THIS IS ONLY FOR UPTO A FIVE DIGIT NO. BY ROHAN ARORA#include#includevoid main(){int a,n,s,sum=0;clrscr();printf("Enter the number between 1 to 5 digits\n");scanf("%d",&a);while(a!=0){n=a%10;sum=sum+n;a=a/10;}printf("The sum of digits of the given numberis %d",sum);getch();}


How do you know if a number is in the 9 times table?

if you add the digits of the number such as 81 8+1=9 every time, the digits of the number will add up to 9


How do you find the sum of digits of each number?

Add the digits together. The sum of the digits of 23 is 5.


Include zeros in 2.25 million?

Million is the name given to a number with 7 digits in front of the decimal place. In order to write out any number take the number you are given and and move the decimal place to the right until you have 7 digits in front of the decimal. add zeros to the end until it has 7 digits in front of the decimal place. So 2.25 million would be 2,250,000.


What is the next year in which all its digits add up to a prime number?

2014 ( The sum of the digits = 7, a prime number )


What happens to the digits when you add 11 over and over to a two digit number?

The number of digits increases - without limit.


What does find the sum of the digits of each number above mean?

Add the digits together. The sum of the digits of 23 is 5.


What number has 2 in the tens place and digits add to 5?

7


What do you notice when you add the digits of the product of 9 and another number?

They add up to 9


What is a number that has one prime number in it the digits add up to 19 it is a palindrome and the composite digits each have 4 factors?

838


How can you check if a number is divisible by 9 when usimg?

Add all the digits of the number together - if the sum of the digits is divisible by 9, then the original number is too.


When you add the number of rows in my array to the number in each row you get 15 My digits add up to 9 Which number am I?

24