Question: rhis is code for lab5e2.c need code to copy please read the question #include //Function prototypes int largest(int *,int); void display(int *,int); void main(int argc,char
rhis is code for lab5e2.c
need code to copy please read the question
#include
//Function prototypes
int largest(int *,int);
void display(int *,int);
void main(int argc,char *argv[]){
//Required variables took max size of array to be 100
int a[100];
char c;
int *p = a,count = 0,i;
//If no command line arguments are passed
if(argc == 1){
//Reads integers from user input
while(scanf("%d",p)){
count++;
p++;
}
}else{
//Else opens the file provided in command line arguments in read mode
FILE *f;
f = fopen(argv[1],"r");
//If file not found
if(f == NULL)
printf("File cannot be opened ");
else{
//Else read integers in file using pointer
while(fscanf(f,"%d",p) == 1){
count++;
p++;
}
//closes the file
fclose(f);
}
}
//Calls display method
display(a,count);
//Calls largest method
int max = largest(a,count);
//Displays the largest value
printf("Largest value : %d ",max);
}
int largest(int *p,int length){
//Required variable
int max = 0,i;
//Loops length times
for(i = 0;i
//If any value of array is bigger that max, place the value to max
if(max
5.3 Problem E2-void (10 pt) Rewrite lab 5E2.C such that function largest is void and has one more parameters. That is, void largest (int *, int, ?) where ? is a type that you decide. Call the funciton properly in main so it has the same input and output as problem E2. Note that function largest should not print anything. Generate output in main as before. Name your program lab2e2void.c and submit using submit 20310N labs lab5Evoid.c 14 max = *p;
}
//Point to next value of array
p++;
}
return max;
}
void display(int *p,int length){
//Required variable
int i;
printf("Inputs: ");
//Loop length times
for(i = 0;i
//Print each array value
printf("%d ",*(p++));
}
printf(" ");
}
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
