# write a C program to obtain the sum of the first and last digit of this number

Rate this post

## Problem Statement:

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.

## Solution:

/* Sum of 1st and last digit of a four digit number */

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

main()
{

int n,a,sum=0;

clrscr();

printf(“\Enter a four digit number”);
scanf(“%d”,&n);

a=n/1000; /* 1st digit */
sum=sum+a; /* sum updated with addition of 1st digit */

a=n%10; /* Last digit */
sum=sum+a; /* sum updated addition with last digit */

printf(“\n Sum of first and last digit of %d=%d”,n,sum);

printf(“\n\n\n\n\n\ Press any key to exit…”);
getch();

}

For any query or issue, feel free to discuss on http://discuss.eduguru.in

#### Satya Prakash

VOIP Expert: More than 8 years of experience in Asterisk Development and Call Center operation Management. Unique Combination of Skill Set as IT, Analytics and operation management.