4. Create a program that will plot the equation of the line y=mx+b using an array.
array1 ==> x - input by user
m = constant - input by user
b = constant - input by user
array2 ==> y - computed
#include <iostream>
using namespace std;
int main(){
float y[100], m, x[100], b;
int i, n;
cout << "Enter m: ";
cin >> m;
cout << "Enter b: ";
cin >> b;
cout << "How many X do you want to enter? ";
cin >> n;
for (i = 0; i < n; i ++){
if (i == 0){
cout << "Enter first X: ";
}
else{
cout << "Enter the following X: ";
}
cin >> x[i];
}
cout << "#################################" << endl;
cout << "# y = mx+b --> y = " << m << "x + " << b << " #" << endl;
cout << "#################################" << endl;
cout << "# X # Y #" << endl;
cout << "#################################" << endl;
for (i = 0; i < n; i++){
cout << "# " << x[i] << "\t\t# " << m*x[i]+b << "\t#" << endl;
}
cout << "#################################" << endl;
return 0;
}
Comments
Leave a comment