#include<stdio.h>
int digit(int,int);
main()
{
int num,pos,dg;
printf("\nEnter a number=");
scanf("%d",&num);
printf("\nEnter the position=");
scanf("%d",&pos);
dg=digit(num,pos);
if(dg==-1)
printf("\nInvalid position");
else
printf("\nDigit found in position %d is %d",pos,dg);
}
int digit(int n,int p)
{
int i=1;
while(i<p && n>=0)
{
n=n/10;
i++;
}
if(n==0)
return -1;
else
return n%10;
}
No comments:
Post a Comment