69,371
社区成员
发帖
与我相关
我的任务
分享
int x, y;
scanf("%d", &x);
if (x >= 100 || x < 36)
{
y = -1;//用-1表示错误值。 根据实际情况,可以用其他值表示错误
printf("x value error!\n");
}
else if (x >=81)
{
y = x+2;
}
else if (x >=64)
{
y = 2*x+3;
}
else if (x >=49)
{
y = 3*x+4;
}
else
{
y = 4*x+5;
}
if (y != -1)
{
printf("y = %d", y);
}
#include <stdio.h>
int main()
{
int x;
int y = 0;
scanf( "%d",&x );
if ( x >= 100 || x < 36 )
{
printf( "Y无定义\n" );
return 0;
}
if ( x >= 81 && x < 100 )
y = x + 2;
else if ( x >= 64 && x < 81 )
y = 2*x + 3;
else if ( x >= 49 && x < 64 )
y = 3*x + 4;
else if ( x >= 36 && x < 49 )
y = 4*x + 5;
printf( "\nwhen x = %d, y = %d",x,y );
return 0;
}