Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

-The count of values is given at the beginning of the file, followed by the valu

ID: 3539031 • Letter: #

Question

-The count of values is given at the beginning of the file, followed by the values themselves.

- The input of this program will be a file containing the integer values. You have to load those values in an array. The first line of the input file (values.txt) will be the count value followed by the actual integer values starting from the second line. A sample file:

10

1 1 2 3 5 8 13 21 34 55

- Print the array in console to make sure that the array is identical to the input values.

-Have the user input a number, then do a search for that number within the array.

- If the input value is found in the array print its index otherwise print %u201Cvalue doesn%u2019t exists%u201D.

Explanation / Answer

#include <iostream>

#include <fstream>

using namespace std;


int main()

{

ifstream in("values.txt");

int count;

in >> count;

int arr[count];

for(int i=0;i<count;i++)

in>>arr[i];


for(int i=0;i<count;i++)

cout<<arr[i]<<" ";

cout<<endl;


int key;

cout<<"Enter a number to search :";

cin>>key;

for(int i=0;i<count;i++)

{

if(arr[i]==key)

{

cout<<key <<" found at position "<<i+1<<endl;

return 0;

}

}

cout<<key<<" not found"<<endl;

return 0;

}