From cf84dc49dee2cf6f29d2e9a2ae35b3271249e4d7 Mon Sep 17 00:00:00 2001 From: Peter Sabol Date: Thu, 10 Mar 2022 11:23:37 +0000 Subject: [PATCH] Update 'du2/program.c' --- du2/program.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/du2/program.c b/du2/program.c index 0d46973..c61f086 100644 --- a/du2/program.c +++ b/du2/program.c @@ -3,20 +3,39 @@ #define VELKOST_POLA 52 int main(){ - int vysledky[VELKOST_POLA]; + /*int vysledky[VELKOST_POLA]; int pocet; int max=0; int i=0; - int c=0; - char pole[100]; + char pole[VELKOST_POLA]; memset(pole,0,VELKOST_POLA * sizeof(int)); for(i max){ max = pole[i]; - c=i; } printf("\nSúťažiaci č.%d vypil %d pohárov.\n", i , pole[i]); } printf("\nVýherca je súťažiaci%d ktorý vypil %d pohárov\n", c , max); return 0; + */ + int n; + double arr[100]; + printf("Enter the number of elements (1 to 100): "); + scanf("%d", &n); + + for (int i = 0; i < n; ++i) { + printf("Enter number%d: ", i + 1); + scanf("%lf", &arr[i]); + } + + // storing the largest number to arr[0] + for (int i = 1; i < n; ++i) { + if (arr[0] < arr[i]) { + arr[0] = arr[i]; + } + } + + printf("Largest element = %.2lf", arr[0]); + + return 0; } \ No newline at end of file