Thursday, September 13, 2018

SUM IT NOW

  • Problem Description

    Nilo and Teena are playing with each other. Nilo challenges Teena to sum the digit of a number. Help Teena to answer as quick as possible.
  • CODING ARENA
  • #include <stdio.h>
    int main()
    {
      int n,t,sum=0,rem;
      scanf("%d",&n);
      t=n;
      while(t!=0)
      {
        rem=t%10;
        sum=sum+rem;
        t=t/10;
      }
      printf("%d",sum);

    return 0;
    }
  • Test Case 1

    Input (stdin)
    300
    
    
    Expected Output
    3
  • Test Case 2

    Input (stdin)
    16789
    
    
    Expected Output
    31

No comments:

Post a Comment