Saturday, August 25, 2018

ADDING DIGITS

  • Problem Description

    Lally is very weak in mathematics. So Raju challenges Lally to add each digit of a number, if she adds correctly she will get a chocolate. Will you help her to get a choci?
  • CODING ARENA
  • #include <stdio.h>
    int main()
    {
      int num,digit,sum=0;
      scanf("%d",&num);
      while(num>0)
      {
        digit=num%10;
        sum=sum+digit;
        num=num/10;
      }
      printf("%d",sum);
    return 0;
    }
  • Test Case 1

    Input (stdin)
    531
    
    
    Expected Output
    9
  • Test Case 2

    Input (stdin)
    623
    
    
    Expected Output
    11

No comments:

Post a Comment