oooodchod
This commit is contained in:
		
							parent
							
								
									da4173541d
								
							
						
					
					
						commit
						5fad030cbc
					
				| @ -1,7 +1,6 @@ | |||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
| #include <string.h> | #include <string.h> | ||||||
| #include <time.h> |  | ||||||
| 
 | 
 | ||||||
| #define SIZE 100 | #define SIZE 100 | ||||||
| 
 | 
 | ||||||
| @ -10,22 +9,21 @@ struct student { | |||||||
|     int votes; |     int votes; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| // Funkcia na inicializáciu databázy mien študentov s náhodným počtom hlasov
 | void initialize_database(struct student* database, int size, char* names[], int* votes) { | ||||||
| void initialize_database(struct student* database, int size) { |  | ||||||
|     srand(time(NULL)); // Inicializácia generátora náhodných čísel
 |  | ||||||
|     char names[5][20] = {"Terian Dis", "John Doe", "Jane Smith", "Alice Johnson", "Bob Brown"}; |  | ||||||
|     for (int i = 0; i < size; i++) { |     for (int i = 0; i < size; i++) { | ||||||
|         strcpy(database[i].name, names[rand() % 5]); // Náhodný výber mena zo zoznamu
 |         strcpy(database[i].name, names[i]); | ||||||
|         database[i].votes = rand() % 21; // Náhodný počet hlasov od 0 do 20
 |         database[i].votes = votes[i]; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int main() { | int main() { | ||||||
|     struct student database[SIZE]; |     struct student database[SIZE]; | ||||||
|     memset(database, 0, SIZE * sizeof(struct student)); |     memset(database, 0, SIZE * sizeof(struct student)); | ||||||
|     int size = 10; // Veľkosť databázy mien študentov
 |     int size = 8; // Veľkosť databázy mien študentov
 | ||||||
|  |     char* names[8] = {"Bardos Mrtakrys", "Rita Umhi", "Prylenn Alak", "Lak'hi Elavorg", "Prylenn Alak", "Prylenn Alak", "Prylenn Alak", "Rita Umhi"}; | ||||||
|  |     int votes[8] = {2, 1, 1, 10, 3, 3, 3, 1}; // Počet hlasov pre každého študenta
 | ||||||
| 
 | 
 | ||||||
|     initialize_database(database, size); // Inicializácia databázy mien študentov
 |     initialize_database(database, size, names, votes); // Inicializácia databázy mien študentov
 | ||||||
| 
 | 
 | ||||||
|     // Výpis databázy
 |     // Výpis databázy
 | ||||||
|     printf("Databaza mien studentov s poctom hlasov:\n"); |     printf("Databaza mien studentov s poctom hlasov:\n"); | ||||||
| @ -33,12 +31,13 @@ int main() { | |||||||
|         printf("%d %s\n", database[i].votes, database[i].name); |         printf("%d %s\n", database[i].votes, database[i].name); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // Načítanie a použitie počtu hlasov zo vstupu
 |     // Vypočítanie celkového počtu hlasov v ankete
 | ||||||
|     int total_votes = 0; |     int total_votes = 0; | ||||||
|     for (int i = 0; i < size; i++) { |     for (int i = 0; i < size; i++) { | ||||||
|         total_votes += database[i].votes; |         total_votes += database[i].votes; | ||||||
|     } |     } | ||||||
|     printf("\nCelkovy pocet hlasov: %d\n", total_votes); | 
 | ||||||
|  |     printf("\nCelkovy pocet hlasov v ankete: %d\n", total_votes); | ||||||
| 
 | 
 | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user