How to get the last digit of a number in C

2 Answers

0 votes
#include <stdio.h>

int main(void)
{
    printf("%d", 12345 % 10);

    return 0;
}

 
/*
run:
    
5

*/

 



answered Nov 17, 2015 by avibootz
0 votes
#include <stdio.h> 
      
int main() 
{ 
    int n = 782005;
 
    int last_digit = n % 10;
 
    printf("%d", last_digit);
        
    return 0; 
} 
      
      
      
/*
run:
      
5
    
*/

 



answered Nov 17, 2015 by avibootz
edited Mar 7, 2024 by avibootz
...