图片太模糊了,大体代码如下:
#include <stdio.h>
int main()
{
int f,x,a;
scanf("%d",&x);
if(x<0)
a = -1;
else if(x == 0)
a = 0;
else
a = 1;
switch(a)
{
case -1:
f = -1;
break;
case 0:
f = 0;
break;
case 1:
f = 2;
break;
}
printf("%d",f);
return 0;
}
int main()
{
float x,y;
scanf("%f",&x);
if(x>0)
y = 2*x;
else if(x==0)
y=0;
else
y = -1;
printf("%f",y);
return 0;
}
用switch-case
#include<iostream>
using namespace std;
int main()
{
float x = 0.0f;
float fx =0.0f;
cin >> x;
int flag;
if(x>0)
flag=1;
else if(x<0)
flag = -1;
else
flag = 0;
switch(flag){ //switch-case
case 1 :
fx = 2*x;
break;
case -1 :
fx = -1;
break;
case 0:
fx =0;
break;
}
cout<<"fx="<<fx;
return 0;
}