usaa19a6/program.c

51 lines
1.4 KiB
C
Raw Normal View History

2019-10-29 13:14:29 +00:00
#include <stdio.h>
2019-10-29 13:20:21 +00:00
#include <stdlib.h>
#include <ctype.h>
2019-10-29 13:24:52 +00:00
#include <string.h>
2019-11-10 14:58:03 +00:00
long long int nsd(long long int,long long int);
2019-10-29 13:20:21 +00:00
2019-11-10 14:58:03 +00:00
long long int nsd(long long int cislo1,long long int cislo2){
while (cislo1 != cislo2){
if (cislo1 > cislo2){
cislo1 -= cislo2;
} else{
cislo2 -= cislo1;
}
2019-10-29 13:20:21 +00:00
}
2019-11-10 14:58:03 +00:00
return cislo1;
}
int main() {
2019-11-10 15:09:19 +00:00
//freopen("vstup.txt","r",stdin);
2019-11-10 14:58:03 +00:00
char* prvy_vstup = malloc(100* sizeof(char));
char* druhy_vstup = malloc(100* sizeof(char));
2019-11-10 15:09:05 +00:00
long long int prve_cislo;
long long int druhe_cislo;
2019-10-29 13:37:38 +00:00
2019-11-10 14:58:03 +00:00
fgets(prvy_vstup,100,stdin);
strtok(prvy_vstup,"\n");
if (!isdigit(*prvy_vstup)){
printf("%s je neplatny zapis.\n",prvy_vstup);
goto koniec;
} else{
2019-11-10 15:09:05 +00:00
printf("Nacitane %llu\n",prve_cislo = strtoll(prvy_vstup,NULL,0));
2019-11-10 14:58:03 +00:00
}
2019-10-29 13:46:53 +00:00
2019-11-10 14:58:03 +00:00
while((fgets(druhy_vstup,100,stdin))){
strtok(druhy_vstup,"\n");
2019-10-29 13:46:53 +00:00
2019-11-10 14:58:03 +00:00
if (!isdigit(*druhy_vstup)){
printf("%s je neplatny zapis.\n",druhy_vstup);
goto koniec;
} else{
2019-11-10 15:09:05 +00:00
long long int vysledok = nsd(prve_cislo,druhe_cislo = strtoll(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);
2019-10-29 13:46:53 +00:00
}
2019-10-29 13:37:38 +00:00
2019-10-29 13:14:29 +00:00
}
2019-11-10 15:00:31 +00:00
printf("Koniec nacitania.\n");
2019-11-10 14:58:03 +00:00
koniec:
2019-11-10 15:09:05 +00:00
free(prvy_vstup);
2019-11-10 14:58:03 +00:00
free(druhy_vstup);
2019-10-29 13:14:29 +00:00
}