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

C Program to enter 4 digit number and display sum of first and last number, Write a program to enter 4 digit number and find sum of the first and last digit of the number.

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

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

i.e 1234 [1+4] = 5,

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


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

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

}

You May Also Like...