SHARE
TWEET

Untitled

AchkataJo Nov 21st, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. int getSum(int n)
  4. {  
  5.    int sum = 0;
  6.    while (n != 0)
  7.    {
  8.        sum = sum + n % 10;
  9.        n = n/10;
  10.    }
  11.    return sum;
  12. }
  13.  
  14. int main()
  15. {
  16.   int n;
  17.   printf("Please choose a number: ");
  18.   scanf("%d",&n);
  19.   printf("The sum of digits is: %d", getSum(n));
  20.   return 0;
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top