Advertisement
Mim527

3.sum of first and last

Jun 21st, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.  
  5.     int num, sum=0, firstDigit, lastDigit;
  6.  
  7.     printf("Enter any number: ");
  8.     scanf("%d", &num);
  9.  
  10.     lastDigit = num % 10;
  11.  
  12.     firstDigit = num;
  13.  
  14.     while(num >= 10)
  15.     {
  16.         num = num / 10;
  17.     }
  18.     firstDigit = num;
  19.  
  20.     sum = firstDigit + lastDigit;
  21.  
  22.     printf("Sum of first and last digit: %d", sum);
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement