C++ Program to Print First Digit of Number using For Loop
Write C++ Program to Print First Digit of Number using For Loop
// CPP Program to Print First Digit of Number using For Loop
#include <iostream>
using namespace std;
int main()
{
int n, remainder;
cout << "Enter the Number :--> ";
cin >> n;
for(; 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