Write a for loop in c that reads in 3 nonnegative integers f

Write a for loop in c++ that reads in 3 non-negative integers from the user (one at a time) and assigns the maximum value to a variable maxVal.

Solution

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

int main()
{

int i,num,maxVal=-10000;

for (i=0;i<3;i++){

   cout << \"Please enter a negative number: \";
   cin >> num;
if (num > maxVal)
       maxVal = num;

}

printf(\"maxVal: %d\ \",maxVal);

return 0;

}

Write a for loop in c++ that reads in 3 non-negative integers from the user (one at a time) and assigns the maximum value to a variable maxVal.Solution#include

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site