How to extract last N digits from a number in C

1 Answer

0 votes
#include <stdio.h>
#include <math.h>

int main(void) {
    int num = 4884721;
    int N = 3;

    int last = num % (int)ceil(pow(10, N));

    printf("%d\n", last);

    return 0;
}




/*
run:

721

*/

 



answered Oct 15, 2021 by avibootz

Related questions

1 answer 139 views
1 answer 145 views
1 answer 151 views
2 answers 177 views
1 answer 130 views
1 answer 137 views
...