usaa19a6/program.c

48 lines
1.2 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-10-29 13:14:29 +00:00
int main() {
char* prve_cislo = malloc(100* sizeof(char));
char* druhe_cislo = malloc(100* sizeof(char));
fgets(prve_cislo,100,stdin);
2019-10-29 13:28:38 +00:00
strtok(prve_cislo,"\n");
2019-10-29 13:20:21 +00:00
if (isalpha(*prve_cislo)){
printf("%s je neplatny zapis.\n",prve_cislo);
free(prve_cislo);
free(druhe_cislo);
return 0;
}
2019-10-29 13:24:52 +00:00
int cislo1 = strtof(strtok(prve_cislo,"\n"),NULL);
2019-10-29 13:37:38 +00:00
printf("Nacitane %d\n",cislo1);
2019-10-29 13:14:29 +00:00
int cislo2;
while((fgets(druhe_cislo,100,stdin))){
2019-10-29 13:46:53 +00:00
2019-10-29 13:24:52 +00:00
cislo2= strtof(strtok(druhe_cislo,"\n"),NULL);
2019-10-29 13:37:38 +00:00
int buf_C_1 = cislo1;
int buf_C_2 = cislo2;
2019-10-29 13:46:53 +00:00
if (isalpha(*druhe_cislo)){
printf("%s je neplatny zapis.\n",prve_cislo);
free(prve_cislo);
free(druhe_cislo);
return 0;
}
2019-10-29 13:14:29 +00:00
while (cislo1 != cislo2){
if (cislo1 > cislo2){
cislo1 -= cislo2;
} else{
cislo2 -= cislo1;
}
}
2019-10-29 13:46:53 +00:00
printf("Nacitane %d\n",cislo2);
2019-10-29 13:37:38 +00:00
printf("Najvacsi spolocny delitel cisel %ld a %ld je %ld\n",buf_C_1,buf_C_2,cislo1);
2019-10-29 13:14:29 +00:00
}
free(prve_cislo);
2019-10-29 13:20:21 +00:00
free(druhe_cislo);
2019-10-29 13:14:29 +00:00
}