How to sum of first and last digit of a number in C

1 Answer

0 votes
#include <stdio.h>
  
int main()
{
	int n = 12758;
	
    int lastDigit = n % 10;

    while(n >= 10) {
        n = n / 10;
    }
    int firstDigit = n;

    int sum = firstDigit + lastDigit; 
	
	printf("%d\n", sum);

    return 0;
}
  
  
  
/*
run:
  
9
  
*/

 



answered Jul 6, 2020 by avibootz

Related questions

1 answer 115 views
2 answers 174 views
3 answers 208 views
2 answers 165 views
1 answer 68 views
1 answer 70 views
...