From c94c624a34659acf1e1e067da4e42b94d989cb28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=A9re=C5=A1?= Date: Sun, 10 Nov 2019 14:58:03 +0000 Subject: [PATCH] Aktualizovat "program.c --- program.c | 78 +++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/program.c b/program.c index b03ecc3..c9674c3 100644 --- a/program.c +++ b/program.c @@ -2,47 +2,47 @@ #include #include #include +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() { - char* prve_cislo = malloc(100* sizeof(char)); - char* druhe_cislo = malloc(100* sizeof(char)); - fgets(prve_cislo,100,stdin); - strtok(prve_cislo,"\n"); - if (isalpha(*prve_cislo)){ - printf("%s je neplatny zapis.\n",prve_cislo); - free(prve_cislo); - free(druhe_cislo); - return 0; + freopen("vstup.txt","r",stdin); + char* prvy_vstup = malloc(100* sizeof(char)); + char* druhy_vstup = malloc(100* sizeof(char)); - } - int cislo1 = strtof(strtok(prve_cislo,"\n"),NULL); - printf("Nacitane %d\n",cislo1); - - int cislo2; - while((fgets(druhe_cislo,100,stdin))){ - - cislo2= strtof(strtok(druhe_cislo,"\n"),NULL); - int buf_C_1 = cislo1; - int buf_C_2 = cislo2; - - if (isalpha(*druhe_cislo)){ - printf("%s je neplatny zapis.\n",druhe_cislo); - free(prve_cislo); - free(druhe_cislo); - return 0; - - } - while (cislo1 != cislo2){ - if (cislo1 > cislo2){ - cislo1 -= cislo2; - } else{ - cislo2 -= cislo1; - } - } - printf("Nacitane %d\n",cislo2); - - printf("Najvacsi spolocny delitel cisel %ld a %ld je %ld\n",buf_C_1,buf_C_2,cislo1); + 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)); } - free(prve_cislo); - free(druhe_cislo); + 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); + + } + + } + koniec: + free(prvy_vstup); + free(druhy_vstup); } \ No newline at end of file