-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPf_assignmentpro3.c
More file actions
139 lines (139 loc) · 2.93 KB
/
Copy pathPf_assignmentpro3.c
File metadata and controls
139 lines (139 loc) · 2.93 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <stdio.h>
// ANS ABDULLAH MALIK
void input(float a[][365])
{
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 365; j++)
{
scanf("%f", &a[i][j]);
}
}
}
void lowest_temp(float a[][365], float b[])
{
int count = 0, f = 0;
float lowest = a[0][0];
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 365; j++)
{
if (a[i][j] > lowest)
{
b[i] = a[i][j];
count++;
if (count == 10)
{
break;
f = 1;
}
}
}
if (f == 1)
break;
}
}
int less_than_0(float a[][365])
{
int count = 0;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 365; j++)
{
if (a[i][j] < 0)
{
count++;
break;
}
}
}
return count;
}
int searchValue(float a[][365], float b)
{
int count = 0;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 365; j++)
{
if (a[i][j] == b)
{
count++;
break;
}
}
}
if (count >= 5)
return 1;
else
return 0;
}
void average_temp(float a[][365], float b[])
{
float sum;
for (int i = 0; i < 10; i++)
{
sum = 0;
for (int j = 0; j < 365; j++)
{
sum += a[i][j];
}
b[i] = sum / 365;
}
}
void display_first_last(float a[][365])
{
printf("Value for 1st and last day for each year is :\n");
for (int i = 0; i < 10; i++)
{
printf("%2.f and %2.f", a[i][0], a[i][365]);
}
}
void display_odd(float a[][365])
{
for (int i = 9; i >= 0; i -= 2)
{
for (int j = 364; j >= 0; j -= 2)
{
printf("%2.f", a[i][j]);
}
}
printf("\n");
}
void output(float a[][365])
{
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 365; j++)
{
printf("%f", a[i][j]);
}
}
}
int main()
{
float Temperature[10][365];
float lowest[10];
input(Temperature);
lowest_temp(Temperature, lowest);
int count = less_than_0(Temperature);
printf("Number of temperature less than 0 is %d\n", count);
float search_value;
printf("Enter value to search in array\n");
scanf("%f", &search_value);
int Return = searchValue(Temperature, search_value);
if (Return == 0)
printf("Respective value is found in more than 5 years\n");
else
printf("Value is not founded for more than 5 years\n");
float average_temps[10];
average_temp(Temperature, average_temps);
printf("Your average values for 10 years are :\n");
for (int i = 0; i < 10; i++)
{
printf("%.2f\n", average_temps[i]);
}
display_first_last(Temperature);
display_odd(Temperature);
output(Temperature);
}