fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. float x;
  5. //we ask for x...
  6. printf("Please enter x: ");
  7. scanf("%f",&x);
  8. //We do the calculation based on the function.
  9. //Because we won't need it any more, we store the result in x.
  10. if (x<-5) x=5*x*x;//first condition...
  11. else if (x>=0) x=3*x+5; //third condition...
  12. else x=x/(6+x);//second condition needn't be tested because we tested the others.
  13. printf("\n\nf(x)=%f",x);
  14. return 0;
  15. }
  16.  
Success #stdin #stdout 0s 4404KB
stdin
-3
stdout
Please enter x: 

f(x)=-1.000000