include stdio include stdlib include string include locale include win

 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <windows.h>
#define N 100
int main(int argc, char *argv[])
{
FILE *file;
char name[N]={};
long int c;
int i;
float mas[N],sum=0;
/* ðîçîâàÿ ìèëîòà */
HANDLE consoleOutput;
consoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(consoleOutput, 1 | FOREGROUND_RED | FOREGROUND_INTENSITY);
/* ïðîâåðêà êîë-âà ïåðåäàííûõ ïàðàìåòðîâ */
if(argc==1)
{
printf(" ‚¢¥¤¨â¥ ¨¬ï ä ©«  ¤«ï ®¡à ¡®âª¨:\n");
scanf("%s", name);
}
if(argc==2)
{
strcpy(name,argv[1]);
}
/* ïðîâåðêà îòêðûòèÿ ôàéëà */
if((file=fopen(name,"rb"))== NULL)
{
printf(" ? a¤ «®ai ®a?aeai\n", name);
system("PAUSE");
return 1;
}
fseek(file , 0, SEEK_END );
c=_filelength(file);
/* êîëè÷åñòâî ýëåìåíòîâ â ôàéëå */
fseek(file , 0, SEEK_SET );
printf(" ᮤ¥à¦¨¬®¥ ä ©«  ¤® ®¡à ¡®âª¨: %d \n", c);
for(i=0;i<c;i++)
{
fscanf(file,"%f", &mas[i]);
printf("%f ", mas[i]);
sum+=mas[i];
}
sum/=c;
printf(" ᮤ¥à¦¨¬®¥ ä ©«  ¯®á«¥ ®¡à ¡®âª¨: \n");
for(i=0;i<c;i++)
{
mas[i]-=sum;
fprintf(file,"%f", mas[i]);
printf("%f ", mas[i]);
}
system("PAUSE");
return 0;
}