C Program to Find Sum of First Digit and Last Digit of a Number

#include<stdio.h>
#include<conio.h>

int main()
{
	 long number, firstDigit, lastDigit, sum;
	 clrscr();
	 printf("Enter any number: ");
	 scanf("%ld", &number);
	
	 /* Finding last digit */
	 lastDigit = number%10;
	
	 /* Finding first digit */
	 while(number>9)
	 {
	  	number = number/10;
	 }
	 firstDigit = number;
	
	 /* Finding sum */
	 sum = firstDigit + lastDigit;
	
	 /* Displaying result */
	 printf("Sum of first digit and last digit is: %ld", sum);
	
	 getch();
	 return(0);
}

Output

Run 1:
-------------
Enter any number: 87986 ↲
Sum of first digit and last digit is: 14

Run 2:
-------------
Enter any number: 88 ↲
Sum of first digit and last digit is: 16

Leave a Reply

Your email address will not be published. Required fields are marked *

https://atozonlinesolutions.com/wp-content/uploads/2017/03/logo_white.png
https://atozonlinesolutions.com/wp-content/uploads/2017/03/logo_white.png
About
Products
Subscribe

If you wish to receive our latest news in your email box, just subscribe to our newsletter. We won’t spam you, we promise!

    Applauz

    As the pioneer of the lean startup movement, APPLAUZ has dedicated it’s time to sharing effective business strategies that help new businesses and enterpreneurs put their money to work in the right way.

    Subscribe

    If you wish to receive our latest news in your email box, just subscribe to our newsletter. We won’t spam you, we promise!

      Applauz

      As the pioneer of the lean startup movement, APPLAUZ has dedicated it’s time to sharing effective business strategies that help new businesses and enterpreneurs put their money to work in the right way.

      Copyright by BOLD THEMES. All rights reserved.