Chapter - 2: C Instructions

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.


H
Sections
3
Exercises
#include<stdio.h>
#include<conio.h>
int main()
{
	int num,a,b,c,d;
	printf("Enter a four digit number : ");
	scanf("%d", &num);
	d=num%10;
	c=(num/10)%10;
	b=(num/100)%10;
	a=(num/1000)%10;
	printf("\n%d is the of first and last digit of %d", a+d,num);
	getch();
	return 0;
}

© 2021 Garbage Valuegarbage value logo