fork download
  1. #include<stdio.h>
  2.  
  3.  
  4.  
  5. int main() {
  6. int first, last, sum, num;
  7. //printf ("Enter 4 digit number");
  8. scanf ("%d",&num);
  9.  
  10. last=num%10;
  11. while(num/10)
  12. {
  13. first=num/10;
  14. num = num/10;
  15. }
  16.  
  17. sum=first+last;
  18. printf("sum of first and last digits = %d", sum);
  19. return 0;
  20. }
Success #stdin #stdout 0s 2160KB
stdin
23578
stdout
sum of first and last digits = 10