Friday, May 3, 2019

Back 2 Back

  • Problem Description

    Rand has a task to find the sum of first and last digit of number upto given n numbers.Help him in
    writing C code to enter any number and find the sum of first and last digit of the number using for loop.
  • Test Case 1

    Input (stdin)
    1234

    Expected Output
    5
  • Test Case 2

    Input (stdin)
    8231

    Expected Output
    9
Solution

#include <stdio.h>
int main()
{
  int n,fd,ld,sum=0;
  scanf("%d",&n);
  ld=n%10;
  fd=n;
  while(n>=10)
  {
    n=n/10;
  }
  fd=n;
  sum=fd+ld;
  printf("%d",sum);

 return 0;
}

No comments:

Post a Comment

Parity

Problem Description Ram and Sita playing the parity game. Two types of parity are there. One is odd parity and next is even parity. Ram will...