From b00fed981b798f7bd692a172face4f2d502ad967 Mon Sep 17 00:00:00 2001 From: kr820js Date: Sun, 3 Mar 2024 16:01:11 +0100 Subject: [PATCH] submit1 --- cv3/program.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 cv3/program.c diff --git a/cv3/program.c b/cv3/program.c new file mode 100644 index 0000000..017d278 --- /dev/null +++ b/cv3/program.c @@ -0,0 +1,57 @@ +#include +#include +#include + +#define SIZE_OF_ARRAY 100 +#define LINE_SIZE 2 + +int main() +{ + float result_of_main; + float x,a,b,c; + int result=reading_input(&x); + if(result==0){ + printf("x"); + return 0; + } + result=reading_input(&a); + if(result==0){ + printf("a"); + return 0; + } + result=reading_input(&b); + if(result==0){ + printf("b"); + return 0; + } + result=reading_input(&c); + if(result==0){ + printf("c"); + return 0; + } + result_of_main=a*(x*x)+b*x+c; + + printf("Vysledok je: %.2f", result_of_main); + return 0; +} +int reading_input(float *number){ + char buffer[SIZE_OF_ARRAY]; + fgets(buffer,SIZE_OF_ARRAY,stdin); + for(int j=0; buffer[j]!='\0'; j++){ + if (buffer[j]>='0'&&buffer[j]<='9') { + continue; + } + if (buffer[j]=='.'||buffer) { + continue; + } + if(buffer[j]=='\n'){ + buffer[j]='\0'; + break; + } + printf("You have entered wrong number.\n"); + return 0; + } + *number=atof(buffer); + return 1; +} +