Cześć potrzebuje pomocy, program ma sprawdzać czy trójkąt z podanych liczb jest prostokątny i ma zapisać w tablicy.
main.c
#include <stdio.h>
#include <math.h>
#include "triangle.h"
int i;
float x1,x2,x3,y1,y2,y3;
Point_t first={x1,y1};
Point_t second={x2,y2};
Point_t third={x3,y3};
int main(){
printf("Wprowadz wartosci 'x' i 'y' dla trzech punktow (zatwierdzaj kazda wartosc enter) \n");
scanf("%f", &x1);
scanf("%f\n", &y1);
scanf("%f", &x2);
scanf("%f\n", &y2);
scanf("%f", &x3);
scanf("%f\n", &y3);
points[]={Point_t first,Point_t second,Point_t third};
bool isRightTriangle(Point_t points[]);
if true {
printf("Trojkat prostokatny);
};
if false {
printf("Trojkat nie jest prostokatny");
};
return 0;
};
triangle.c
#include <stdio.h>
#include <math.h>
#include "triangle.h"
double calculateDistance (Point_t first,Point_t second){
const double xDist = second.x - first.x ;
const double yDist = second.y - first.y ;
return sqrt(xDist*xDist + yDist*yDist);
};
double side1,side2,side3;
bool isRightTriangle(Point_t points[]){
side1=calculateDistance(Point_t first, Point_t second);
side2=calculateDistance(Point_t first, Point_t third);
side3=calculateDistance(Point_t second, Point_t third);
if {
(sqrt(pow(side1)+pow(side2))==side3)||(sqrt(pow(side3)+pow(side2))==side1)||(sqrt(pow(side1)+pow(side3))==side2);
return true;
};
if else {
return false;
};
};
triangle.h
#pragma once
// Declaration of boolean type
#include <stdbool.h>
typedef struct Point {
double x, y;
} Point_t;
bool isRightTriangle(Point_t points[]);
tak wygląda polecenie.
Plik triangle.h zawiera deklaracje struktury Point t, przechowującej współrzędne punktu na płaszczyźnie, oraz funkcji bool isRightTriangle(Point t points[]), która sprawdza czy trzy zadane punkty na płaszczyźnie tworzą trójkąt prostokątny. Punkty przekazywane są w postaci tablicy struktur Point t. Napisz definicję funkcji isRightTriangle() i umieść ją w pliku triangle.c, a następnie przetestuj działanie zaimplementowanej funkcji. Współrzędne x, y punktów pobierz z klawiatury. Dla uproszczenia możesz przyjąć, że działanie funkcji jest niezdefiniowane w przypadku, gdy tablica punktów ma rozmiar różny niż 3