-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinimum Loss.c
49 lines (47 loc) · 987 Bytes
/
Minimum Loss.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
#include<stdio.h>
#include<stdarg.h>
#include<stdlib.h>
void main()
{
int numYear;
int subValue=0;
int loss=0;
int finalLoss = 0;
int temp = 1;
int temp2 = 1;
scanf("%d",&numYear);
int rateArr[numYear];
int lossArr[numYear];
for(int i=0;i<numYear;i++)
{
scanf("%d",&rateArr[i]);
}
for(int i=0;i<numYear;i++)
{
int num1 = rateArr[i];
for(int j=i+1;j<numYear;j++)
{
subValue = num1 - rateArr[j];
if(subValue > 0)
{
if(temp)
{
loss = subValue;
temp = 0;
}
else if(subValue < loss)
{
loss = subValue;
}
}
}
if(temp2)
{
finalLoss = loss;
temp2=0;
}
else if(finalLoss > loss)
finalLoss = loss;
}
printf("%d",finalLoss);
}