Anik_Akash

Summing Digits

May 16th, 2020
107
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     long long int n, sum=0, i;
  6.      while(scanf("%lld", &n) !=EOF){
  7.         if(n<=0) break;
  8.      else{
  9.        while(n>9){
  10.         while(n>0){
  11.             i = n%10;
  12.             n = n/10;
  13.             sum = sum+i;
  14.         }
  15.         n =sum;
  16.         sum =0;
  17.      }
  18.      printf("%lld\n", n);
  19.      }
  20.      }
  21.  
  22.     return 0;
  23. }
RAW Paste Data