WAP to find the first and last digit of the integer using while loop

Write a program to find the first and last digit of the integer using while loop

#include<stdio.h>

void main() {
	int n,first,last;
	printf("Enter any number: ");
	scanf("%d",&n);
	first=n;
	last=n%10;
	while(first>=10)
		first/=10;
	printf("First digit = %d \nLast digit = %d",first,last);	
}

Output

Enter any number: 23449
First digit = 2
Last digit = 9

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments