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

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

}

TutsMaster.org

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.