submit1
This commit is contained in:
parent
c5c92845f8
commit
b00fed981b
57
cv3/program.c
Normal file
57
cv3/program.c
Normal file
@ -0,0 +1,57 @@
|
||||
#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", 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user