58 lines
1.1 KiB
C
58 lines
1.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
|
|
#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\n", 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;
|
|
}
|
|
|