usaa19a6/program.c

75 lines
2.1 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 15:54:25 +00:00
#include <limits.h>
unsigned long long int nsd(long long int,long long int);
2019-10-29 13:20:21 +00:00
2019-11-10 15:54:25 +00:00
unsigned long long int nsd(long long int cislo1,long long int cislo2){
2019-11-10 15:20:30 +00:00
/*while (cislo1 != cislo2){
2019-11-10 14:58:03 +00:00
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;
2019-11-10 15:20:30 +00:00
*/
if (cislo1 == 0)
return cislo2;
return nsd(cislo2 % cislo1, cislo1);
2019-11-10 14:58:03 +00:00
}
int main() {
2019-11-10 15:56:00 +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:54:25 +00:00
unsigned long long int prve_cislo;
unsigned long long int druhe_cislo;
2019-10-29 13:37:38 +00:00
2019-11-10 15:26:13 +00:00
if (fgets(prvy_vstup,100,stdin)){
strtok(prvy_vstup,"\n");
if (!isdigit(*prvy_vstup)){
printf("%s je neplatny zapis.\n",prvy_vstup);
goto koniec;
2019-11-10 15:59:02 +00:00
}
else if (prve_cislo = strtoull(prvy_vstup,NULL,0) == ULLONG_MAX){
printf("%s je mimo rozsahu.\n",prvy_vstup);
goto koniec;
}
else{
2019-11-10 15:54:25 +00:00
printf("Nacitane %llu\n",prve_cislo = strtoull(prvy_vstup,NULL,0));
2019-11-10 15:26:13 +00:00
}
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))){
2019-11-10 15:33:58 +00:00
if (*druhy_vstup =='\n'){
printf("Koniec nacitania.\n");
goto koniec;
}
2019-11-10 14:58:03 +00:00
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:54:25 +00:00
if (druhe_cislo = strtoull(druhy_vstup,NULL,0) == ULLONG_MAX){
2019-11-10 15:55:34 +00:00
printf("%s je mimo rozsahu.\n",druhy_vstup);
2019-11-10 15:54:25 +00:00
goto koniec;
}
2019-11-10 15:59:02 +00:00
else{
2019-11-10 15:54:25 +00:00
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);
}
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
}