Q:

Write C program to find the sum of first and last digit of any number

0

Write C program to find the sum of first and last digit of any number

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int main(void) {
 
    int num, sum=0, firstDigit, lastDigit;
 
    printf("Enter any number: ");
    scanf("%d", &num);
 
    lastDigit = num % 10;
 
    firstDigit = num;
 
    while(num >= 10)
    {
        num = num / 10;
    }
    firstDigit = num;
 
     //Finding sum of first and last digit
    sum = firstDigit + lastDigit;
 
    printf("Sum of first and last digit: %d", sum);
    return 0;
}

Result:

Enter any number: 123456

Sum of first and last digit: 7

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write C program to find first and last digit of an... >>
<< Write C program to swap first and last digit of a ...