Programming

C – Enter 4 Digit Number and Display Sum of First and Last Number

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

}

Tuts

About Author

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