Showing posts with label Coordinate. Show all posts
Showing posts with label Coordinate. Show all posts

C Program Coordinates of the Vertices

How to write a coordinates of the vertices in C Programming Language ?

This C Program Coordinates of the Vertices.

Solution:


  1. #include <stdio.h>
  2. #define SIZE 100 //ограничение на количество вершин в файле (16)
  3. #define PNUM 100 //ограничение на количество точек фигуры (42)
  4. //площадь = 38
  5. int find_arr_size (int arr[], int* arr_size) //определяем реальное количество вершин
  6. {
  7.     int i = 0;
  8.     *arr_size = SIZE;
  9.     for (= 0 ; i < SIZE ; i++)
  10.     {
  11.         if ((arr[i] == 0) && (arr[i+1] == 0) && (arr[i+2] == 0) && (arr[i+3] == 0))
  12.         {
  13.             *arr_size = i;
  14.             break;
  15.         }
  16.     }
  17.     return *arr_size;
  18. }
  19. int main()
  20. {
  21.     FILE *figure;
  22.     figure = fopen("figure.txt", "r");
  23.     int arr[SIZE] = {0};
  24.     int arr_size = 65;
  25.     int i, j, k, s;
  26.     i = 0;
  27.     while (fscanf(figure, "%d", &arr[i]) != EOF) //получили координаты вершин
  28.     {
  29.         //printf("%d ", arr[i]);
  30.         i++;
  31.     }
  32.     fclose(figure);
  33.     arr_size = find_arr_size(arr, &arr_size); //знаем количество вершин
  34.     printf("arr_size : %d", arr_size);
  35.  
  36.     return 0;
  37. }

Add x and y coordinates to create a new struct in C Program

How to Add x and y coordinates to create a new struct in C Programming Language ?


/*Supply two cartesian_t structs and add x and y coordinates to create a new struct*/

  1. struct cartesian_t add(struct cartesian_t a, struct cartesian_t b){
  2.         struct cartesian_t coordsSum;
  3.         coordsSum.x = (a.x) + (b.x);
  4.         coordsSum.y = (a.y) + (b.y);
  5.         return coordsSum;
  6. }