Write a program that searches a 5X1 integer array and finds themaximum value. Th
ID: 3615707 • Letter: W
Question
Write a program that searches a 5X1 integer array and finds themaximum value. The program should be set up as follows (noticeI don’t require any functions be used. You may use themif you wish):
1. Fill the array by reading the 5values from a data file.
2. Find the maximum value of thearray.
3. Display the maximum value andthe array (as a 5X1).
Test your program using the following data:
Run 1: 19 Run 2: 16.8
24 13.2
1 20
10 12.7
#include <iostream>
using namespace std;
#include <fstream.h>
ifstream datain;
int main()
//variables
{float data[5],max;
int i;
i=0;
//data input
datain.open("somefilename.cpp",ios::in);
for(i=0;i<=4;i++)
{datain>>data[i];
cout<<data[i]<<" ";
}
datain.close();
//output
max=data[0];
for(i=1;i<=4;i++)
{if (max<data[i])
{max=data[i];
}
}
cout<<"the max is "<<max<<" ";
system("pause");
}
Explanation / Answer
Dear...
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.