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

Given an input file name input2.txt containing two rows of numbers: 10 50 20 40

ID: 3658029 • Letter: G

Question

Given an input file name input2.txt containing two rows of numbers: 10 50 20 40 30 30 40 20 50 10 Write a program that reads the numbers in input2.txt and stores the numbers in each row in an array. For example, you can create two arrays named arrA and arrB, and arrA contains numbers in the first row (10, 20, 30, 40, 50) and arrB contains numbers in the second row (50, 40, 30, 20, 10) as in input2.txt. If the numbers in arrA and arrB are the same but in reverse order, your program should output a message indicating the reverse order relation. However, if input2.txt contains the following numbers: 10 10 or 10 10 20 20 20 15 30 30 30 10 40 40 40 30 50 50 50 10

Explanation / Answer

/* Given an input file name input2.txt containing two rows of numbers: 10 50 20 40 30 30 40 20 50 10 Write a program that reads the numbers in input2.txt and stores the numbers in each row in an array. For example, you can create two arrays named arrA and arrB, and arrA contains numbers in the first row (10, 20, 30, 40, 50) and arrB contains numbers in the second row (50, 40, 30, 20, 10) as in input2.txt. If the numbers in arrA and arrB are the same but in reverse order, your program should output a message indicating the reverse order relation. However, if input2.txt contains the following numbers: 10 10 or 10 10 20 20 20 15 30 30 30 10 40 40 40 30 50 50 50 10 */ #include #include void create(){//creates input2.txt for testing purposes char info[]="10 50 20 40 30 30 40 20 50 10"; // char info[]="10 10 20 20 30 30 40 40 50 50"; // char info[]="10 10 20 15 30 10 40 30 50 10"; FILE *out; out=fopen("input2.txt","w"); fprintf(out,info); fclose(out); } void displayArr(int arr[],int size);//displays array int getfileInfo(int arrA[], int arrB[], int *size);//gets infomation from file int isRevRelation(const int arrA[],const int arrB[], int size);//check if in reverse relation int isIdentical(const int arrA[], const int arrB[], int size);//check if idential int main(){ create();//for testing purpose const int MAXSIZE=100; int arrA[MAXSIZE],arrB[MAXSIZE]; int actualSize, opened; opened=getfileInfo(arrA,arrB,&actualSize); if(opened==0){ printf("File failed to open Press any key to exit..."); } printf(" arrA: "); displayArr(arrA,actualSize); printf(" arrB: "); displayArr(arrB,actualSize); if(isRevRelation(arrA,arrB,actualSize)==1){ printf(" arrA and arrB has a reverse relationship. "); } printf(" arrA and arrB are "); if(isIdentical(arrA,arrB,actualSize)==0) printf("not "); printf("identical. "); getch(); return 0; } void displayArr(int arr[],int size){//displays array int i; printf(" [ "); for(i=0;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote