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() { | int main() { | ||||||
|     double x; |     double x; | ||||||
|  |      | ||||||
|  |     // Načítanie hodnoty x zo štandardného vstupu
 | ||||||
|     if (scanf("%lf", &x) != 1) { |     if (scanf("%lf", &x) != 1) { | ||||||
|         printf("Chyba: Neplatná hodnota x.\n"); |         printf("Chyba: Neplatná hodnota x.\n"); | ||||||
|         return 1; |         return 1; | ||||||
|     } |     } | ||||||
|      |  | ||||||
|     // Pole koeficientov
 |  | ||||||
|     double coefficients[] = {2, 1, 1}; // Zmena koeficientov
 |  | ||||||
| 
 | 
 | ||||||
|     // Počet koeficientov
 |     // Načítanie koeficientov polynómu
 | ||||||
|     int degree = sizeof(coefficients) / sizeof(coefficients[0]);  |     double coefficients[MAX_COEFFICIENTS]; | ||||||
|  |     int degree; | ||||||
| 
 | 
 | ||||||
|     double result = evaluate_polynomial(x, coefficients, degree - 1); |     printf("Zadajte stupeň polynómu: "); | ||||||
|  |     if (scanf("%d", °ree) != 1) { | ||||||
|  |         printf("Chyba: Neplatný stupeň polynómu.\n"); | ||||||
|  |         return 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); |     printf("Vysledok je: %.2f\n", result); | ||||||
| 
 | 
 | ||||||
|     return 0; |     return 0; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user