Created
December 5, 2012 16:04
-
-
Save vertrigo/4216915 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <conio.h> | |
| #include <math.h> | |
| void main(void) | |
| { | |
| FILE *f,*g; | |
| f=fopen("lab8.dat","w"); | |
| printf("Вводите целые числа, признак конца - 0:\n"); | |
| int k; | |
| float x; | |
| do { | |
| scanf("%i",&k); | |
| if (k!=0) | |
| { | |
| x=(pow(-1,k)*pow(0.3,k))/(k+1); | |
| fwrite(&x,sizeof(x),1,f); | |
| } | |
| } while (k); | |
| fclose(f); | |
| printf("Содержимое файла:\n"); | |
| if ((f=fopen("lab8.dat","r"))==NULL) | |
| { | |
| printf("Ошибка при открытии файла!\n"); | |
| return; | |
| } | |
| g=fopen("lab8.txt","w"); | |
| fprintf(g,"Содержимое файла:\n"); | |
| float p=1; | |
| do { | |
| fread(&x,sizeof(x),1,f); | |
| if (!feof(f)) | |
| { | |
| printf("%8.3f",x); | |
| fprintf(g,"%8.3f",x); | |
| p*=x; | |
| } | |
| } while (!feof(f)); | |
| printf("\nПроизведение компонентов файла = %8.4f\n",s); | |
| fprintf(g,"\nПроизведение компонентов файла = %8.4f\n",s); | |
| fclose(f); fclose(g); | |
| getch(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment