Print sum of first & last digit of any number - C

Write a C program to calculate sum of first and last digit of a given number.

Solution:

#include<stdio.h>
int main()
{
      int s=0,l;
      long n;
      printf("Enter Number : ");
      scanf("%ld",&n);         //5697
      if(n>10)
      {
            l=n%10;            //l=7
      }
      while(n>=10)       // 5697>=10 // 569>=10 // 56>=10 //5>=10
      {
            n=n/10;           // n= 569 // 56 //  5
      }
      s=l+n; //12 = 7+5
      printf("\nFirst Digit : %ld \nLast Digit  : %d",n,l);
      printf("\n\nSum of First and Last Digit  : %d",s);
      return 0;
}


Output:

sum first last digit