Back 2 Back

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

Program :


#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;

}