Write a function that reads real (fractional) numbers, 𝑥1, 𝑥2, … , 𝑥𝑁 from the keyboard
into an array of N, starting from index 0. The numbers are read after a prompt.
#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter the number of data to be entered: ";
cin>>n;
float data[n];
for (int i=0;i<n;i++){
cout<<"Enter data number "<<i+1<<": ";
cin>>data[i];
}
//display the entered data
cout<<"Entered data:"<<endl;
for (int i=0;i<n;i++){
printf("%.2f", data[i]);
cout<<"\t";
}
return 0;
}
Comments
Leave a comment