Write a C program to read in a 2-dimestional arrays and store this array in ARY
ID: 3660529 • Letter: W
Question
Write a C program to read in a 2-dimestional arrays and store this array in ARY whose dimensions M and N are read in. A) Write a function called COPYR that will copy all the elements of the given double array ARY row by row to a single array called VCTR B) Write a function called COPYC that will copy all the elements of the Given double array ARY column by column to a single array called VCTC C) Write a function called POLYNOMIAL that will calculate all the elements of the double array ARY one by one with the given polynomial function called POLY. You will store the new double array values to CALCULATED double arrays. POLY(X) = 2X3 + 5X2 + 3Sin(X)Explanation / Answer
#include #include #include const int M=3; const int N=4; void COPYR(double[][N],double[]); void COPYC(double[][N],double []); void POLYNOMIAL(double[][N],double[][N]); int main(){ FILE *infile, *outfile; //FILE streams char inputfile[100],outputfile[100]; //two strings for names of files //2-D double arrays declaration double ARY[M][N]; double CALCULATED[M][N]; //1-D double array declaratiosn double VCTR[M*N]; double VCTC[M*N]; int i,j; //counter variables //ask for input file name printf("Enter input file name: "); scanf("%s",inputfile); //note that you do not need the & (for address of) here because infile is a pointer infile=fopen(inputfile,"r"); //try to open infile for reading //get output file name printf("Enter output file name: "); scanf("%s",outputfile); //also does not need & infront of outfile outfile=fopen(outputfile,"w");//open file for writing //closes out if input file failes to open if(infile==NULL){ printf(" Input file failed to open. Press any key to continue . . ."); fprintf(outfile," Input file failed to open. Press any key to continue . . ."); //output echo getch();//gets one key press return 0; } printf("Input file opened successfully. Now, loading data..."); fprintf(outfile,"Input file opened successfully. Now, loading data..."); //output echo //Note that this program does not check that the inputfile is in the correct format e.g. has M*N floats for(i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.