Skip to content

Instantly share code, notes, and snippets.

@thomaswpp
Created January 31, 2017 00:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save thomaswpp/45bd8e6b1c8e46a9c895029f97d0196e to your computer and use it in GitHub Desktop.
#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