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

Write a C program that prints out the max and min values of the data file includ

ID: 3686742 • Letter: W

Question

Write a C program that prints out the max and min values of the data file included below. Do not use computations within the main function, instead use the programmer-define functions (reference functions with function prototypes) to solve it. You can choose anyone of the three data file structures (counter, sentinel, and neither counter/sentinel) to be included in your solution.

130.5 120 140 140.4 140.8 150.2 140 121 160.3 150 - 160.9 170 160.9 130.4 180 170 190.6 190 180 150.6 - 110 150 110 120.1 150.1 170.7 130 190 180 170

Explanation / Answer

#include<stdio.h>
#include<file.h>
max(int [],int)
min(int [],int)
void main()
{
   int a[1000];
   int number,x,y;
   int i=0;
   FILE* in_file=fopen("name",r);
       if(! in_file)
       {
           printf("file cannot be read ");
           exit(-1);
       }
       while(fscanf(file,"%d",& number)==1)
           {
               printf("we just read",number);
               a[i]=number;
               i=i+1;
          
           }
          
       fclose(in_file);
       x=max(a,i);
       y=min(a,i);
       printf("max,min are %d,%d",x,y);
       getch();
          
}
max(int x[],int k)
{
   int t,i;
   t=x[0];
   for(i=1;i<k;i++)
   {
       if(x[i]>t)
           t=x[i];
   }
   return(t);
}
min(int x[],int k)
{
   int t,i;
   t=x[0];
   for(i=1;i<k;i++)
   {
       if(x[i]<t)
           t=x[i];
   }
   return(t);
  
}

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