首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

有道题写出来感觉下没有关问题,可就是出错不知道为什么

2013-03-14 
有道题写出来感觉上没问题,可就是出错不知道为什么#include stdio.hmain(){int x,yscanf(%d,&x)if(x

有道题写出来感觉上没问题,可就是出错不知道为什么
有道题写出来感觉下没有关问题,可就是出错不知道为什么

#include <stdio.h>
main()
{int x,y;
scanf("%d",&x);
if(x<1) y=x;
if(x>=1&&x<10) y=2x-11;
if(x>=10) y=3x-11;
printf("%d\n",y);}
[解决办法]


#include <stdio.h>
int main()
{
    int x,y;
    scanf("%d",&x);
    if(x < 1) y = x;
    if(x >= 1 && x < 10) y = 2*x-11;
    if(x >= 10) y = 3*x-11;
    printf("%d\n",y);
}

[解决办法]
这样试试:

#include <stdio.h>
main()
{
    int x,y;
    scanf("%d",&x);

    if(x < 1) 
      y = x;

    if(x >= 1 && x < 10) 
      y = 2 * x-11; //*

    if(x >= 10) 
       y = 3 * x-11;//*

    printf("%d\n", y);

热点排行