Answer to Question #300654 in C for Manoj

Question #300654

Write a function that takes a positive integer as input and return the leading digit in its decimal representation

1
Expert's answer
2022-02-21T11:04:33-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS