编写一个可以运行的c语言程序

img

img


用c语言怎么写?


#include <stdio.h>
#include <math.h>
int main()
{
    float x,z;
    scanf("%f",&x);
    if(x>=1&&x<2)
    z=3.0*x+5.0;
    if(x>=2&&x<3)
    z=2.0*sin(x)-1.0;
    if(x>=3&&x<5)
    z=pow(1.0+x*x,0.5);
    if(x>=5&&x<8)
    z=x*x-2*x+5;
    printf("%.2f",z);
 } 

img


#include<stdio.h>
#include<math.h>
void main(){
int x;
float z;
scanf("%d",&x);
if(x>=1&&x<2){
  z= 3*x+5;
}
else if(x>=2&& x<3)
{
  z= (2*sin(x)-1);
}
else if(x>=3&&x<5){
  z=sqrt(1+x*x);
}
else if(x>=5&& x<8)
{
 z = x*x-2*x +5;
}
else
{
  printf("input %d is not int (1,8)",x);
 return;
}
printf("z is %lf",z);
return;

}