3
This commit is contained in:
		
							parent
							
								
									2dbcd57084
								
							
						
					
					
						commit
						69f09317a0
					
				| @ -13,18 +13,35 @@ double evaluate_polynomial(double x, double coefficients[], int degree) { | ||||
| 
 | ||||
| int main() { | ||||
|     double x; | ||||
|      | ||||
|     // Načítanie hodnoty x zo štandardného vstupu
 | ||||
|     if (scanf("%lf", &x) != 1) { | ||||
|         printf("Chyba: Neplatná hodnota x.\n"); | ||||
|         return 1; | ||||
|     } | ||||
| 
 | ||||
|     // Pole koeficientov
 | ||||
|     double coefficients[] = {2, 1, 1}; // Zmena koeficientov
 | ||||
|     // Načítanie koeficientov polynómu
 | ||||
|     double coefficients[MAX_COEFFICIENTS]; | ||||
|     int degree; | ||||
| 
 | ||||
|     // Počet koeficientov
 | ||||
|     int degree = sizeof(coefficients) / sizeof(coefficients[0]);  | ||||
|     printf("Zadajte stupeň polynómu: "); | ||||
|     if (scanf("%d", °ree) != 1) { | ||||
|         printf("Chyba: Neplatný stupeň polynómu.\n"); | ||||
|         return 1; | ||||
|     } | ||||
| 
 | ||||
|     double result = evaluate_polynomial(x, coefficients, degree - 1); | ||||
|     printf("Zadajte koeficienty polynómu: "); | ||||
|     for (int i = 0; i <= degree; i++) { | ||||
|         if (scanf("%lf", &coefficients[i]) != 1) { | ||||
|             printf("Chyba: Neplatný koeficient polynómu.\n"); | ||||
|             return 1; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     // Vyhodnotenie polynómu pre zadanú hodnotu x
 | ||||
|     double result = evaluate_polynomial(x, coefficients, degree); | ||||
| 
 | ||||
|     // Výpis výsledku
 | ||||
|     printf("Vysledok je: %.2f\n", result); | ||||
| 
 | ||||
|     return 0; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user