fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int num;
  5. int first_digit;
  6. int last_digit;
  7. int sum;
  8.  
  9. printf("Enter a number: ");
  10. scanf("%d", &num);
  11.  
  12. // find the first digit of the number
  13. first_digit = num;
  14. while (first_digit >= 10) {
  15. first_digit /= 10;
  16. }
  17.  
  18. // find the last digit of the number
  19. last_digit = num % 10;
  20.  
  21. // calculate the sum of the first and last digits
  22. sum = first_digit + last_digit;
  23.  
  24. printf("Sum of first and last digit: %d\n", sum);
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5292KB
stdin
45
stdout
Enter a number: Sum of first and last digit: 9