Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <stdlib.h>
- #include <stdio.h>
- typedef struct point
- {
- int x;
- int y;
- } point;
- typedef struct line
- {
- point p1;
- point p2;
- } line;
- typedef struct reads
- {
- line *p;
- int n;
- FILE *in;
- FILE *out;
- float s;
- } reads;
- void read(reads *c)
- {
- fopen_s(&c->in, "C:\\Users\\Infidelis\\Desktop\\input.txt", "r");
- fscanf_s(c->in, "%d", &c->n);
- c->p = (line*)malloc(c->n * sizeof(line));
- for (int i = 0; i < c->n; i++)
- fscanf_s(c->in, "%d%d%d%d", &c->p[i].p1.x, &c->p[i].p1.y, &c->p[i].p2.x, &c->p[i].p2.y);
- fclose(c->in);
- }
- float sum(reads *c)
- {
- c->s = 0;
- for (int i = 0; i < c->n; i++)
- c->s = c->s + sqrt(pow(c->p[i].p1.x - c->p[i].p2.x, 2) + pow(c->p[i].p1.y - c->p[i].p2.y, 2));
- return c->s;
- }
- void end(reads *c)
- {
- fopen_s(&c->out, "C:\\Users\\Infidelis\\Desktop\\output.txt", "w");
- fprintf_s(c->out, "%f", sum(c));
- fclose(c->out);
- free(c);
- }
- void main()
- {
- reads *c = (reads*)malloc(sizeof(reads));
- read(c);
- sum(c);
- end(c);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement