Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning(disable:4996)
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #define PI 3.14159265
- struct Triangle {
- double a, b, c;
- double alpha, beta, gamma;
- char a_filled, b_filled, c_filled;
- char alpha_filled, beta_filled, gamma_filled;
- };
- void input(struct Triangle* t) {
- printf("(a): ");
- scanf("%lf", &t->a);
- if (t->a > 0) t->a_filled = 1;
- printf("(b): ");
- scanf("%lf", &t->b);
- if (t->b > 0) t->b_filled = 1;
- printf("(c): ");
- scanf("%lf", &t->c);
- if (t->c > 0) t->c_filled = 1;
- printf("alpha: ");
- scanf("%lf", &t->alpha);
- if (t->alpha > 0) t->alpha_filled = 1;
- printf("beta: ");
- scanf("%lf", &t->beta);
- if (t->beta > 0) t->beta_filled = 1;
- printf("gamma: ");
- scanf("%lf", &t->gamma);
- if (t->gamma > 0) t->gamma_filled = 1;
- }
- void output(const struct Triangle* t) {
- printf("\na = %g, b = %g, c = %g\n", t->a, t->b, t->c);
- printf("alpha = %g, beta = %g, gamma = %g\n", t->alpha, t->beta, t->gamma);
- }
- bool isValidTriangle(struct Triangle* t) {
- return (((t->a + t->b > t->c) && (t->a + t->c > t->b) && (t->b + t->c > t->a)) || (t->alpha + t->beta + t->gamma > 180));
- }
- void missel(struct Triangle* t) {
- if (!isValidTriangle) {
- if (t->a_filled && t->b_filled && t->alpha_filled) {
- t->c = sqrt(pow(t->a, 2) + pow(t->b, 2) - 2 * t->a * t->b * cos(t->alpha * PI / 180));
- t->c_filled = 1;
- t->beta = asin(sin(t->alpha * PI / 180) * t->b / t->c) * 180 / PI;
- t->beta_filled = 1;
- t->gamma = 180 - t->alpha - t->beta;
- t->gamma_filled = 1;
- }
- else if (t->a_filled && t->c_filled && t->beta_filled) {
- t->b = sqrt(pow(t->a, 2) + pow(t->c, 2) - 2 * t->a * t->c * cos(t->beta * PI / 180));
- t->b_filled = 1;
- t->alpha = asin(sin(t->beta * PI / 180) * t->a / t->b) * 180 / PI;
- t->alpha_filled = 1;
- t->gamma = 180 - t->alpha - t->beta;
- t->gamma_filled = 1;
- }
- else if (t->b_filled && t->c_filled && t->gamma_filled) {
- t->a = sqrt(pow(t->b, 2) + pow(t->c, 2) - 2 * t->b * t->c * cos(t->gamma * PI / 180));
- t->a_filled = 1;
- t->beta = asin(sin(t->gamma * PI / 180) * t->b / t->a) * 180 / PI;
- t->beta_filled = 1;
- t->alpha = 180 - t->beta - t->gamma;
- t->alpha_filled = 1;
- }
- else {
- printf("Triangle doesn't exists\n");
- }
- }
- else {
- printf("Triangle doesn't exists\n");
- }
- }
- int main() {
- struct Triangle t;
- memset(&t, 0, sizeof(t));
- input(&t);
- output(&t);
- missel(&t);
- if (!isValidTriangle) output(&t);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement