du2
This commit is contained in:
parent
bbb4e03a1a
commit
84016c50eb
48
du2/program.c
Normal file
48
du2/program.c
Normal file
@ -0,0 +1,48 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
void bubbleSort(int arr[], int n){
|
||||
int i, j;
|
||||
int temp;
|
||||
for (i = 0; i < n-1; i++) {
|
||||
for (j = 0; j < n - i - 1; j++) {
|
||||
if (arr[j] > arr[j + 1]) {
|
||||
temp = arr[j];
|
||||
arr[j] = arr[j + 1];
|
||||
arr[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
char** glass = (char**) calloc (50, sizeof(char));
|
||||
|
||||
int numbers[50];
|
||||
int counter = 0;
|
||||
int max_number = 0;
|
||||
int max_position = 1;
|
||||
|
||||
for (int i = 0; fgets(glass[i], 20, stdin) != NULL; i++){
|
||||
for (int j = 0; j < strlen(glass[i]; j++)){
|
||||
if (!isdigit(glass[i][j]) || atoi (glass[i]) < 1){
|
||||
goto LABEL;
|
||||
}
|
||||
}
|
||||
numbers[counter++] = atoi(glass[i]);
|
||||
if (i == 0)
|
||||
max_number = numbers[counter-1];
|
||||
else if(numbers[counter-1] > max_number){
|
||||
max_number = numbers[counter-1];
|
||||
printf("Súťažiaci č. %d vypil %d pohárov.\n",max_position,max_number);
|
||||
}
|
||||
}
|
||||
LABEL:
|
||||
|
||||
bubbleSort(numbers, sizeof(numbers)/sizeof(numbers[0]));
|
||||
|
||||
printf ("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n",max_posistion,numbers[counter-1]);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user