How to extract a single digit from a number

Divide a number by 10 will give you a digit as int sample:
256/10=25.6==25
25/10=2.5==2

256%10=6
25%10=5
2%10=2

This video will surely help:

Code:

#include<stdio.h>
int main(){
int N,R;
printf("Enter the number to reverse: ");
scanf("\n%d",&N);
R=0;
while(N!=0)
{
    R=R*10+N%10;
    N=N/10;
}
printf("Reverse: %d",R);

return 0;
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *