Q3 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.

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.

Program: 61

If a four digit number is input through the keyboard, write a c program to obtain the sum of the first and last digit of this number.| Let us C Solution

#include<stdio.h>
int main()
{
    int n, f, l, sum, num, d=1;
    printf("Enter a number: ");
    scanf("%d", &n);

    num = n;
    while(num!=0)
    {
        num = num/10;
        d = d*10;
    }
    d = d/10;
    f = n/d;
    l = n%10;
    sum = f+l;

    printf("Sum of first and last digit of %d is: %d",n,sum);
}

Output

 Enter a number: 12345
Sum of first and last digit of 12345 is: 6

Lokesh Kumar: Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.
Related Post
Leave a Comment

This website uses cookies.