C Programming

C Program to enter 4 digit number and display sum of first and last number

C Code

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

void main()
{

int n, r, sum = 0;

printf("Enter 4 digit number: ");
scanf("%d",&n);

r= n/1000;

sum = sum+r;

r= n%10;

sum=sum+r;

printf("sum of first and last digit : %d", sum);

getch();

}

Output

Write a program to enter 5 digit number and find sum of the first and last digit of the number.

C Code

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

void main()
{

int n, r, sum = 0;

printf("Enter 5 digit number: ");
scanf("%d",&n);

r= n/10000;

sum = sum+r;

r= n%10;

sum=sum+r;

printf("sum of first and last digit : %d", sum);

getch();

}

Related Articles

Back to top button

Adblock Detected

Please turn off your Adblocker to view your content.