Advertisement
AedenCak3

write a program to obtain the sum of the first and last digit of this number

Dec 1st, 2021
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.37 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int n, first_dig,last_dig,sum=0;
  6.  
  7.  
  8.     printf("Enter any number: ");
  9.     scanf("%d", &n);
  10.  
  11.     first_dig = n;
  12.  
  13.  
  14.     while(first_dig >= 10)
  15.     {
  16.         first_dig = first_dig / 10;
  17.         last_dig =n%10;
  18.         sum=first_dig+last_dig;
  19.     }
  20.  
  21.  
  22.  
  23.    printf("First & Last digit summation = %d",sum);
  24.  
  25.     return 0;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement