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

4)Write a C program that declares three double1-D arrays of size n=10, namely A[

ID: 3558421 • Letter: 4

Question

4)Write a C program that declares three double1-D arrays of size n=10, namely A[n], B[n], and C[n]. Further, the program reads real numbers from keyboard to fill arrays A and B. Then adds the two arrays and assigns them into a third array. Lastly prints the result.

5. Write a C program that reads in 10 double values in a one dimensional array and then searches and prints out the maximum and minimum values from the array on the standard output. Repeat the above program by reading from a file, a 1-D array and then search and print out the maximum and the minimum values from the array on the standard output.

Explanation / Answer


#include<stdio.h>
int main()
{
int i;
//4)Write a C program that declares three double1-D arrays of size n=10, namely A[n], B[n], and C[n].
const int n = 10;
float A[n],B[n],C[n];
for(i=0; i<10; i++)
{
//Further, the program reads real numbers from keyboard to fill arrays A and B.
printf(" Enter value for array 1 at index %d:",(i+1));
scanf("%f",&A[i]);
printf(" Enter value for array 2 at index %d:",(i+1));
scanf("%f",&B[i]);
}
//Then adds the two arrays and assigns them into a third array.
for(i=0; i<10; i++)
C[i] = A[i] + B[i];
for(i=0; i<10; i++)
printf("%f ",C[i]);
return 0;
}


//5. Write a C program that reads in 10 double values in a one dimensional array and then searches and prints out the
//maximum and minimum values from the array on the standard output

#include<stdio.h>
int main()
{
float max = 0;
float min = 0;
float A[10];
int i;
for(i=0; i<10; i++)
{
//Further, the program reads real numbers from keyboard to fill arrays A.
printf(" Enter value for array 1 at index %d:",(i+1));
scanf("%f",&A[i]);
}
max = A[0];
min = A[0];
for(i=0; i<10; i++)
{
   if(A[i] > max ) max = A[i];
   if(A[i] < min ) min = A[i];
}
printf(" Maximum is %f and minimum is %f",max,min);
return 0;
}

//Repeat the above program by reading from a file, a 1-D array and then search and print out the maximum and
//the minimum values from the array on the standard output.

#include<stdio.h>
int main()
{
float max = 0;
float min = 0;
float A[10];
   FILE *fp;
   int i=0;
   fp = fopen("input.txt", "r");
   if( fp != NULL ){
      while ( !feof(fp ) ){
       fscanf(fp,"%f",&A[i++]);
      }
      fclose(fp);
   }
max = A[0];
min = A[0];
for(i=0; i<10; i++)
{
   if(A[i] > max ) max = A[i];
   if(A[i] < min ) min = A[i];
}
printf(" Maximum is %f and minimum is %f",max,min);
return 0;
}

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