#include<stdio.h>floatf1(floatx){//不用巢狀iffloatt;if(-5<x&&x<0)t=x;if(x==0)t=x-1;if(0<x&&x<10)t=x+1;returnt;}floatf2(floatx){//巢狀iffloatt;if(-5<x&&x<10){t=x+1;if(-5<x&&x<=0){t=x-1;if(-5<x&&x<0){t=x;}//第三層}//第二層}//第一層returnt;}floatf3(floatx){//if~else語句floatt;if(-5<x&&x<0)t=x;elseif(x==0)t=x-1;elseif(0<x&&x<10)t=x+1;returnt;}floatf4(floatx){//switch語句floatt;intflag=(x<0?-1:x==0?0:1);switch(flag){case(-1):t=x;break;case(0):t=x-1;break;case(1):t=x+1;break;}returnt;}intmain(){floatx,y;scanf("%f",&x);y=f1(x);printf("%f\n",y);y=f2(x);printf("%f\n",y);y=f3(x);printf("%f\n",y);y=f4(x);printf("%f\n",y);return0;}
#include
float f1(float x){ //不用巢狀if
float t;
if(-5
#include<stdio.h>floatf1(floatx){//不用巢狀iffloatt;if(-5<x&&x<0)t=x;if(x==0)t=x-1;if(0<x&&x<10)t=x+1;returnt;}floatf2(floatx){//巢狀iffloatt;if(-5<x&&x<10){t=x+1;if(-5<x&&x<=0){t=x-1;if(-5<x&&x<0){t=x;}//第三層}//第二層}//第一層returnt;}floatf3(floatx){//if~else語句floatt;if(-5<x&&x<0)t=x;elseif(x==0)t=x-1;elseif(0<x&&x<10)t=x+1;returnt;}floatf4(floatx){//switch語句floatt;intflag=(x<0?-1:x==0?0:1);switch(flag){case(-1):t=x;break;case(0):t=x-1;break;case(1):t=x+1;break;}returnt;}intmain(){floatx,y;scanf("%f",&x);y=f1(x);printf("%f\n",y);y=f2(x);printf("%f\n",y);y=f3(x);printf("%f\n",y);y=f4(x);printf("%f\n",y);return0;}