sahajjain01

10.Input a number and calculate sum of it's digits.

Aug 16th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. //Program to input a number and calculate sum of it's digits.
  2. #include<stdio.h>
  3. #include<conio.h>
  4.  
  5. void main()
  6. {
  7.     int number, sum = 0;
  8.  
  9.     clrscr();
  10.  
  11.     printf("Enter number: ");
  12.     scanf("%d", &number);
  13.  
  14.     while(number != 0)
  15.     {
  16.         sum = sum + (number % 10);
  17.         number = number / 10;
  18.     }
  19.  
  20.     printf("The sum of the digits of the number %d is: %d", number, sum);
  21.  
  22.     getch();
  23. }
Advertisement
Add Comment
Please, Sign In to add comment