If a four-digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of this number.


/*Program to calcuilate sum of first and last digit number

  Author: Priyanshu Date: October 31, 2020*/



#include<stdio.h>

#include<conio.h>


main()

  {

     int num,sum,d1,d2,d3,d4;

     clrscr();

     printf("Enter four digit number:");

     scanf("%d",&num);

     d1 = num % 10;

     num = num / 10;

     d2 = num % 10;

     num = num / 10;

     d3 = num % 10;

     num = num / 10;

     d4 = num % 10;

     sum = d1 +d2-d2 +d3-d3 + d4;

     printf("\nSum of first and last digit number = %d",sum);

     getch();

     return(0);

  }


 

Comments