Week 8 In-Class Examples

Built-in math functions:

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(void)
{
   float a_number;
   float b_number;

   cout << "Enter a number ";
   cin >> a_number;
   cout << "Enter another number ";
   cin >> b_number;

   cout << a_number << " raised to the " << b_number ;
   cout << " is " << pow(a_number,b_number) << endl;

   cout << "The square root of " << a_number << " is ";
   cout << setprecision(12) << sqrt(a_number) << endl;

   return 0;
}

Randon Numbers:

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int main(void)
{
   srand(time(NULL));
   cout << rand()<< endl;
   cout << rand()<< endl;
   cout << rand()<< endl;
   cout << rand()<< endl;
   cout << rand()<< endl;
   return 0;

  }