C++ Program to Print First Digit of Number using While Loop

C++ Program to Print First Digit of Number using While Loop

Write C++ Program to Print First Digit of Number using While Loop

//  CPP Program to Print First Digit of Number using While Loop

#include <iostream>

using namespace std;

int main()
{
	int n, remainder;
	cout << "Enter the Number :--> ";
	cin >> n;

	while(n > 0)
	{
		remainder = n % 10;
		n = n / 10;
	}
	cout << "The first digit of the number is : " << remainder;
	return 0;
}

Output:

Enter the Number :--> 65
The first digit of the number is : 6