From 242f17c83a3a613901904e20cffb502d79804378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=A9re=C5=A1?= Date: Sun, 10 Nov 2019 15:54:25 +0000 Subject: [PATCH] Aktualizovat "program.c --- program.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/program.c b/program.c index 6703e72..802456c 100644 --- a/program.c +++ b/program.c @@ -2,9 +2,10 @@ #include #include #include -long long int nsd(long long int,long long int); +#include +unsigned long long int nsd(long long int,long long int); -long long int nsd(long long int cislo1,long long int cislo2){ +unsigned long long int nsd(long long int cislo1,long long int cislo2){ /*while (cislo1 != cislo2){ if (cislo1 > cislo2){ cislo1 -= cislo2; @@ -22,8 +23,8 @@ int main() { //freopen("vstup.txt","r",stdin); char* prvy_vstup = malloc(100* sizeof(char)); char* druhy_vstup = malloc(100* sizeof(char)); - long long int prve_cislo; - long long int druhe_cislo; + unsigned long long int prve_cislo; + unsigned long long int druhe_cislo; if (fgets(prvy_vstup,100,stdin)){ strtok(prvy_vstup,"\n"); @@ -31,7 +32,7 @@ int main() { printf("%s je neplatny zapis.\n",prvy_vstup); goto koniec; } else{ - printf("Nacitane %llu\n",prve_cislo = strtoll(prvy_vstup,NULL,0)); + printf("Nacitane %llu\n",prve_cislo = strtoull(prvy_vstup,NULL,0)); } } @@ -46,9 +47,20 @@ int main() { printf("%s je neplatny zapis.\n",druhy_vstup); goto koniec; } else{ - 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); + if (druhe_cislo = strtoull(druhy_vstup,NULL,0) == ULLONG_MAX){ + printf("%s je mimo rozsahu.",druhy_vstup); + goto koniec; + + } + else if (prve_cislo == ULLONG_MAX){ + printf("%s je mimo rozsahu.",prvy_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); + } + }