Write a program in C that will read a file containing floati

Write a program in C++ that will read a file containing floating point numbers, store the numbers into an array, count how many numbers were in the file, then output the numbers in reverse order. Your program should only use one array and that array should not be changed after the numbers have been read. Assume that the file does not contain more than 100 floating point numbers. The file name is Arrays.txt

Solution

#include<bits/stdc++.h>
using namespace std;


int main()
{
ifstream f;
float num;
f.open(\"Array.txt\"); //opens .txt file

float arr[100]={0};

int counter=0;
if(f.is_open())
   {
           while(f>>num)
       {
          arr[counter++]=num;
         
       }
}


for(int i=counter-1;i>=0;i--)
        cout<<arr[i]<<endl;


return 0;
}

Write a program in C++ that will read a file containing floating point numbers, store the numbers into an array, count how many numbers were in the file, then o

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site