Write a function that takes a positive integer as input and return the leading digit in its decimal representation
#include<stdio.h>
int getLeadingDigit(int number)
{
int digit;
while(number)
{
digit=number%10;
number=number/10;
}
return digit;
}
int main(){
int number;
printf("Enter any positve integer number : ");
scanf("%d",&number);
printf("The leading digit of number %d is: %d ",number, getLeadingDigit(number));
scanf("%d",&number);
return 0;
}
Comments
Leave a comment