include stdio include stdlib define int main int argc char argv FILE i

  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
#include <stdio.h>
#include <stdlib.h>
#define N 5
int main(int argc, char *argv[]) {
FILE *f;
int i, F=-1,L=-2,flag = 1,k=0;
double A[N];
double temp,sum=0,sr;
f=fopen("otr.txt","w+");
if (f==NULL)
{
puts("Error with opening file!");
return 1;
}
for (i=0;i<N;i++)
scanf("%lf",&A[i]);
for (i=0;i<N;i++)
{
fprintf(f,"%lf",A[i]);
}
for (i=0;i<N;i++)
{
fscanf(f,"%lf", &A[i]);
}
for (i=0;i<N;i++)
{
printf("%lf ",A[i]);
}
for (i=0;i<N;i++)
{
if (A[i] < 0)
{
F=i;
break;
}
}
if (F==-1)
{
printf("There are no negative numbers!");
}
for (i=N-1;i>=0;i--)
{
if (A[i] < 0)
{
L=i;
break;
}
}
if (F==L)
{
printf("There is only one negative number");
}
else
if (A[F]==A[L])
{
printf("no sense");
flag = 0;
}
else
{
temp = A[F];
A[F]=A[L];
A[L]=temp;
}
if (flag)
{ printf("Massive:\n");
for (i=0;i<N;i++)
printf("%lf ", A[i]);
}
for (i=0;i<N;i++)
if (A[i]<0)
{
sum+=A[i];
k++;
}
sr=sum/k;
for (i=0;i<N;i++)
{
fprintf(f,"%lf",A[i]);
}
fclose(f);
f=fopen("otr.txt","a+");
if (f==NULL)
{
puts("Error with opening file!");
return 1;
}
fprintf(f,"%lf",sr);
fclose(f);
return 0;
}