pvjc24/cv5/program.c
2024-03-20 17:49:34 +01:00

37 lines
1.1 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 100
struct student {
char name[SIZE];
int votes;
};
void initialize_database(struct student* database, int size, char* names[], int* votes) {
for (int i = 0; i < size; i++) {
strcpy(database[i].name, names[i]);
database[i].votes = votes[i];
}
}
int main() {
struct student database[SIZE];
memset(database, 0, SIZE * sizeof(struct student));
int size = 9; // Veľkosť databázy mien študentov
char* names[9] = {"Bardos Mrtakrys", "Rita Umhi", "Prylenn Alak", "Lak'hi Elavorg", "Prylenn Alak", "Prylenn Alak", "Prylenn Alak", "Rita Umhi", "Terian Dis"};
int votes[9] = {2, 1, 1, 10, 3, 3, 3, 1, 10}; // Počet hlasov pre každého študenta
initialize_database(database, size, names, votes); // Inicializácia databázy mien študentov
// Výpis databázy
printf("Databaza mien studentov s poctom hlasov:\n");
for (int i = 0; i < size; i++) {
printf("%d %s\n", database[i].votes, database[i].name);
}
return 0;
}