Ok so I played around with this for a while and it works..but I wana know the logic
#include <iostream>
using namespace std;
int main()
{
int number;
int max = 0;
cout << "enter number: ";
cin >> number;
while (number !=0)
{
if ((number % 10)> max) //rem of 10
{
max = (number % 10);
}
number /= 10;
}
cout << "larggest" << max;
return 0;
}
1)
int number;
int max = 0;
why do you need int max..why doesnt max = 0 work?
2)
while (number !=0)
what does !=0 mean?
3)
if ((number % 10)> max) //rem of 10
{
max = (number % 10);
}
number /= 10;
how exactly does that work to print the largest number?