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


Introduction

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


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int main(void) {
  6.  
  7. int num, sum=0, firstDigit, lastDigit;
  8.  
  9. printf("Enter any number: ");
  10. scanf("%d", &num);
  11.  
  12. lastDigit = num % 10;
  13.  
  14. firstDigit = num;
  15.  
  16. while(num >= 10)
  17. {
  18. num = num / 10;
  19. }
  20. firstDigit = num;
  21.  
  22. //Finding sum of first and last digit
  23. sum = firstDigit + lastDigit;
  24.  
  25. printf("Sum of first and last digit: %d", sum);
  26. return 0;
  27. }
  28.  

Result

C language

     





Related Topics




Popular Posts