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

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

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

  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


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.