Write a C program that asks the user to enter an integer number greater than 9, then calculates the sum of the first and the last digits of the number.
Running example:
Input a number greater than 9: -12
Input a number greater than 9: 925
Sum of the first and the last digits: 14
Difficulty level
![](images/star2.png)
This exercise is mostly suitable for students
#include <stdio.h>
int main()
{
int nb, sum;
do{
printf("Input a positive number: ");
scanf("%d",&nb);
}while(nb<10);
sum = nb%10;
while(nb>=10)
nb/=10;
sum +=nb;
printf("Sum of the first and the last digits: %d", sum);
return 0;
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
![](images/star4.png)