final10
This commit is contained in:
parent
2e7bc6ba67
commit
50f25f5afc
@ -1,20 +1,45 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int is_valid_number(const char *s) {
|
||||
char *endptr;
|
||||
if (s[0] == '\0' || s[0] == '\n') return 1;
|
||||
strtod(s, &endptr);
|
||||
while (*endptr == ' ' || *endptr == '\t' || *endptr == '\n') endptr++;
|
||||
return *endptr == '\0';
|
||||
}
|
||||
|
||||
int main(){
|
||||
double x = 0, a = 0, b = 0, c = 0, y;
|
||||
if (scanf("%lf", &x) != 1 && x != 0){
|
||||
printf("Nepodarilo sa načítať x");
|
||||
return 0;
|
||||
} else if (scanf("%lf", &a) != 1 && a != 0){
|
||||
printf("Nepodarilo sa načítať a");
|
||||
return 0;
|
||||
} else if(scanf("%lf", &b) != 1 && b != 0){
|
||||
printf("Nepodarilo sa načítať b");
|
||||
return 0;
|
||||
} else if(scanf("%lf", &c) != 1 && c != 0){
|
||||
printf("Nepodarilo sa načítať c");
|
||||
return 0;
|
||||
}
|
||||
char line[100];
|
||||
double x = 0, a = 0, b = 0, c = 0, y;
|
||||
|
||||
fgets(line, 100, stdin);
|
||||
if(!is_valid_number(line)){
|
||||
return 0;
|
||||
}
|
||||
x = strtod(line, NULL);
|
||||
|
||||
fgets(line, 100, stdin);
|
||||
if(!is_valid_number(line)){
|
||||
return 0;
|
||||
}
|
||||
a = strtod(line, NULL);
|
||||
|
||||
fgets(line, 100, stdin);
|
||||
if(!is_valid_number(line)){
|
||||
printf("Nepodarilo sa načítať b");
|
||||
return 0;
|
||||
}
|
||||
b = strtod(line, NULL);
|
||||
|
||||
fgets(line, 100, stdin);
|
||||
if(!is_valid_number(line)){
|
||||
printf("Nepodarilo sa načítať c");
|
||||
return 0;
|
||||
}
|
||||
c = strtod(line, NULL);
|
||||
|
||||
y = x*x*a+b*x+c;
|
||||
printf("Vysledok je: %.2f\n", y);
|
||||
return 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user