Created
January 31, 2017 00:07
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
/*int mdc(int n1, int n2){ | |
int resto = n1 % n2; | |
while(resto!=0){ | |
n1 = n2; | |
n2 = resto; | |
resto = n1 % n2; | |
} | |
return n2; | |
}*/ | |
int calc_mdc(int n1, int n2, int n3){ | |
int div, mdc = 1; | |
for(div = 2; div <= n1; div ++){ | |
if((n1 % div == 0) && (n2 % div == 0) && (n3 % div == 0)) | |
mdc = div; | |
} | |
return mdc; | |
} | |
int is_pitagora(int n1, int n2, int n3){ | |
int result = pow(n1, 2) + pow(n2, 2); | |
if (result == pow(n3, 2)) | |
return 1; | |
return 0; | |
} | |
int main() | |
{ | |
int n1, n2, n3, mdc, result; | |
while( scanf("%d %d %d", &n1, &n2, &n3) != EOF){ | |
result = is_pitagora(n1, n2, n3); | |
if (!result){ | |
printf("tripla\n"); | |
} else { | |
mdc = calc_mdc(n1, n2, n3); | |
if (mdc != 1) | |
printf("tripla pitagorica\n"); | |
else | |
printf("tripla pitagorica primitiva\n"); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment