Saturday, August 18, 2018

SUM OF THE FIRST AND LAST DIGIT


  • Problem Description

    If Give an integer N . Write a program to obtain the sum of the first and last digit of this number
  • CODING ARENA
  • #include <stdio.h>
    #include<math.h>
    int main()
    {
      int a,b,c,i,e;
      scanf("%d",&a);
      for(i=0;i<a;i++)
      {
        scanf("%d",&b);
        c=b%10;
        while(b>=10)
        {
          b=b/10;
        }
        e=c+b;
        printf("%d\n",e);
      }
      
      
      
      

    return 0;
    }
  • Test Case 1

    Input (stdin)
    2
    
    1234
    
    124894
    
    
    Expected Output
    5
    
    5
  • Test Case 2

    Input (stdin)
    1
    
    23233
    
    
    Expected Output
    5

2 comments:

  1. #include
    int main()
    {

    int n,last,first,sum;

    sum=0;
    scanf("%d",&n);
    last=n%10;
    while(n>=10)
    {

    n=n/10;

    }
    // n=fist;
    sum=n+last;
    printf("%d the sum of the first and last digits\n",sum);
    return 0;
    }

    ReplyDelete