49 lines
1.4 KiB
C
49 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <ctype.h>
|
|
#include <string.h>
|
|
long long int nsd(long long int,long long int);
|
|
|
|
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;
|
|
}
|
|
int main() {
|
|
//freopen("vstup.txt","r",stdin);
|
|
char* prvy_vstup = malloc(100* sizeof(char));
|
|
char* druhy_vstup = malloc(100* sizeof(char));
|
|
|
|
fgets(prvy_vstup,100,stdin);
|
|
strtok(prvy_vstup,"\n");
|
|
if (!isdigit(*prvy_vstup)){
|
|
printf("%s je neplatny zapis.\n",prvy_vstup);
|
|
goto koniec;
|
|
} else{
|
|
printf("Nacitane %llu\n",strtoll(prvy_vstup,NULL,10));
|
|
}
|
|
|
|
while((fgets(druhy_vstup,100,stdin))){
|
|
strtok(druhy_vstup,"\n");
|
|
|
|
if (!isdigit(*druhy_vstup)){
|
|
printf("%s je neplatny zapis.\n",druhy_vstup);
|
|
goto koniec;
|
|
} else{
|
|
long long int vysledok = nsd(strtoll(prvy_vstup,NULL,10),strtoll(druhy_vstup,NULL,10));
|
|
printf("Nacitane %llu\n",strtoll(druhy_vstup,NULL,10));
|
|
printf("Najvacsi spolocny delitel cisel %llu a %llu je %llu\n",strtoll(prvy_vstup,NULL,10),strtoll(druhy_vstup,NULL,10),vysledok);
|
|
|
|
}
|
|
|
|
}
|
|
printf("Koniec nacitania.\n");
|
|
koniec:
|
|
free(prvy_vstup);
|
|
free(druhy_vstup);
|
|
} |