Skip to content

Instantly share code, notes, and snippets.

@vertrigo
Created November 21, 2012 16:26
Show Gist options
  • Select an option

  • Save vertrigo/4125837 to your computer and use it in GitHub Desktop.

Select an option

Save vertrigo/4125837 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
void main()
{
int x,y,k=0;
FILE *f,*g;
f=fopen("lab5.dat","w");
printf("Введите X Y (признак окончания ввода X=0 Y=0):\n");
do {
scanf("%i %i",&x,&y);
if (x != 0 || y != 0)
{
fwrite(&x,sizeof(x),2,f);
fwrite(&y,sizeof(y),2,f);
}
} while (x != 0 || y != 0);
fclose(f);
printf("Содержимое файла:\n");
if ((f=fopen("lab5.dat","r"))==NULL)
{
printf("Ошибка чтения файла\n");
return;
}
g=fopen("lab5.txt","w");
fprintf(g," Содержимое файла:\n");
do {
fread(&x,sizeof(x),2,f);
fread(&y,sizeof(y),2,f);
if(!feof(f))
{
printf("x= %1i ",x);
printf("y= %1i\n",y);
fprintf(g,"%1i ",x);
fprintf(g,"%1i\n",y);
if ( sqrt( pow(x-2,2)+pow(y-2,2) ) >=2.0 ) k++;
}
} while (!feof(f));
printf("\n Количество точек вне круга: %i\n",k);fprintf(g,"\nКоличество точек вне круга: %i\n",k);
fclose(f); fclose(g);
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment