13. Оператори за цикъл while. Факториел и максимална стойност.
Прости цикли - оператор while
while (условие) оператор
* Факториел
#include <iostream>
using namespace std;
long factorial(int n)
{  int factor = 1;
   long product = 1;

   while (factor <= n)
   {  product = product * factor;
      factor++;     }
   return product;
}

int main()
{  cout << "Please enter a number: ";
   int n;
   cin >> n;
   cout << n << "! = " << factorial(n) << "\n";
   return 0;
}

* Максимална стойност
#include <iostream>
using namespace std;
int main()
{  double next;
   double highest;

   cout << "Please enter the temperature values:\n";
   if (cin >> next)   highest = next;
   else
   {  cout << "No data!\n";
      return 1;    }

   while (cin >> next)
       if (next > highest)   highest = next;

   cout << "The highest temperature is " << highest << "\n";
   return 0;
}