
int F(int x)
{
if(x < 2)
return x;
else
{
if(x % 2 == 0)
return G(x / 2) * 2;
else
return G((x - 1) / 2);
}
}
int G(int x)
{
if(x < 2)
return x;
else
{
if(x % 2 == 0)
return G(x / 2) + 1;
else
return x;
}
}
#include
int F(int x);
int G(int x);
int F(int x){
if(x<2)
return x;
else if(x>=2&&x%2==0)
return G(x/2)*2;
else
return G((x/2)/2);
}
int G(int x){
if(x<2)
return x;
else if(x>=2&&x%2==0)
return G(x/2)+1;
else
return x;
}
void main(){
int x;
printf("测试F(x)函数和G(X)函数,请输入一个整数:\n");
scanf("%d",&x);
printf("F(%d) = %d\n",x,F(x));
printf("G(%d) = %d\n",x,G(x));
}
你要的答案只写F(X)和G(X),中间的那段程序就可以了。
if判断