-
Notifications
You must be signed in to change notification settings - Fork 3
/
Week 4 Q2.c
63 lines (47 loc) · 901 Bytes
/
Week 4 Q2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<stdio.h>
void main(){
FILE *fp;
fp = fopen("open.txt","a+");
int i,n;
printf("Input No. Of Entries... \t");
scanf("%d\n",n);
int input[n];
printf("Input Entries...\n");
for(i=0;i<n;i++){
scanf("%d\n",input[i]);
fprintf(fp,"%d\n",input[i]);
}
fclose(fp);
char o;
printf("L/S?\n");
scanf("%c\n",o);
int g = findlarsmal(n,input,o);
fp = fopen("open.txt","a+");
if(o=='l'){
printf("Largest is %d",g);
fprintf(fp,"Largest number is %d\n",g);
}
if(o=='s'){
printf("Smallest is %d",g);
fprintf(fp,"Smallest Number is %d\n",g);
}
fclose(fp);
}
int findlarsmal(int n, int input[(n-1)], int o){
int x;
int big=input[0],small=input[0];
for(x=0;x<n;x++){
if(big<input[x]){
big=input[x];
}
if(small>input[x]){
small=input[x];
}
}
if(o=='l'){
return big;
}
if(o=='s'){
return small;
}
}