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

**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();

}

## Related Posts

- 82Problem Statement : If a five-digit number is input through the keyboard, write a program to reverse the number. Answer: /* To reverse the digits of 5-digit number */ #include<stdio.h> #include<conio.h> main() { int n,a,b; long int revnum=0; clrscr(); printf("\n Enter a five digit number less than 32767"); scanf("%d",&n); a=n%10;…
- 75Problem Statement: If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits. Answer: /* Sum of digits of a 5 digit number*/ #include<stdio.h> #include<conio.h> main() { int num,a,n; int sum=0; /* this has been initialised to zero otherwise it will contain…
- 71
- 66Problem Statement : Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D. Answer: /* Interchanging of contents of two variables c & d */ #include<stdio.h> #include<conio.h> main() { int c,d,e; clrscr(); printf("\n Enter the number…
- 65