How to get the second digit of int number in C

1 Answer

0 votes
#include <stdio.h>
 
int main(void) {
    int number = 76594;
    char s[10];
    int N = 2;
     
    sprintf(s, "%d", number); 
    printf("%c\n", s[N - 1]);
     
    int x = s[N - 1] - '0';
    printf("%d\n", x);
      
    return 0;
}
  
  
  
/*
run:
  
6
6
  
*/

 



answered May 28, 2020 by avibootz
edited Jun 1, 2020 by avibootz

Related questions

1 answer 154 views
1 answer 159 views
1 answer 98 views
1 answer 142 views
1 answer 215 views
2 answers 200 views
...