fork(4) download
  1. #include <stdio.h>
  2. #include <math.h>
  3. int main(void) {
  4. int i,ans,p,N,no_of_digits=0,temp;
  5. printf("Enter two positive integers: ");
  6. scanf("%d%d",&N,&p);
  7. temp=N;
  8. no_of_digits=(int)log10(N) + 1;
  9. while(i<=(no_of_digits-p))
  10. {
  11. ans=N%10;
  12. N=N/10;
  13. i++;
  14. }
  15. printf("The digit of %d in the position %d is %d\n",temp,p,ans);
  16. }
  17.  
Success #stdin #stdout 0s 2116KB
stdin
1234 2
stdout
Enter two positive integers: The digit of 1234 in the position 2 is 2