1. 程式人生 > >C語言:分段函式

C語言:分段函式

題目:在這裡插入圖片描述

#include <math.h>
int main()
{
	double x,y;
    scanf("%lf",&x);
	if (x<0)
	    y=0.5*(-x);
	else 
	    if (x<10)
	       y=exp(x)+3;
	    else 
		    if(x<20)
	          y=log10(x);
	        else 
			    if (x<30)
	              y=pow(x,1.5);
	            else 
				   	if (x<50)  
	                    y=pow (x,0.5)-1;
	                else
	                    y=3*cos(x);
    printf("y=%lf\n",y);
	return 0;
}