75 lines
2.1 KiB
C
75 lines
2.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <ctype.h>
|
|
#include <string.h>
|
|
#include <limits.h>
|
|
unsigned long long int nsd(long long int,long long int);
|
|
|
|
unsigned long long int nsd(long long int cislo1,long long int cislo2){
|
|
/*while (cislo1 != cislo2){
|
|
if (cislo1 > cislo2){
|
|
cislo1 -= cislo2;
|
|
} else{
|
|
cislo2 -= cislo1;
|
|
}
|
|
}
|
|
return cislo1;
|
|
*/
|
|
if (cislo1 == 0)
|
|
return cislo2;
|
|
return nsd(cislo2 % cislo1, cislo1);
|
|
}
|
|
int main() {
|
|
//freopen("vstup.txt","r",stdin);
|
|
char* prvy_vstup = malloc(100* sizeof(char));
|
|
char* druhy_vstup = malloc(100* sizeof(char));
|
|
unsigned long long int prve_cislo;
|
|
unsigned long long int druhe_cislo;
|
|
|
|
if (fgets(prvy_vstup,100,stdin)){
|
|
strtok(prvy_vstup,"\n");
|
|
if (!isdigit(*prvy_vstup)){
|
|
printf("%s je neplatny zapis.\n",prvy_vstup);
|
|
goto koniec;
|
|
}
|
|
else if (prve_cislo = strtoull(prvy_vstup,NULL,0) == ULLONG_MAX){
|
|
printf("%s je mimo rozsahu.\n",prvy_vstup);
|
|
goto koniec;
|
|
}
|
|
|
|
else{
|
|
printf("Nacitane %llu\n",prve_cislo = strtoull(prvy_vstup,NULL,0));
|
|
}
|
|
}
|
|
|
|
while((fgets(druhy_vstup,100,stdin))){
|
|
if (*druhy_vstup =='\n'){
|
|
printf("Koniec nacitania.\n");
|
|
goto koniec;
|
|
}
|
|
strtok(druhy_vstup,"\n");
|
|
|
|
if (!isdigit(*druhy_vstup)){
|
|
printf("%s je neplatny zapis.\n",druhy_vstup);
|
|
goto koniec;
|
|
} else{
|
|
if (druhe_cislo = strtoull(druhy_vstup,NULL,0) == ULLONG_MAX){
|
|
printf("%s je mimo rozsahu.\n",druhy_vstup);
|
|
goto koniec;
|
|
|
|
}
|
|
else{
|
|
unsigned long long int vysledok = nsd(prve_cislo,druhe_cislo = strtoull(druhy_vstup,NULL,0));
|
|
printf("Nacitane %llu\n",druhe_cislo);
|
|
printf("Najvacsi spolocny delitel cisel %llu a %llu je %llu\n",prve_cislo,druhe_cislo,vysledok);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
printf("Koniec nacitania.\n");
|
|
koniec:
|
|
free(prvy_vstup);
|
|
free(druhy_vstup);
|
|
} |