| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1646 人关注过本帖
标题:求助:“当x位于1到20之间时,将x的值赋给变量y;如果x不在这个范围内,则保 ...
取消只看楼主 加入收藏
dani337
Rank: 1
等 级:新手上路
帖 子:20
专家分:9
注 册:2011-10-25
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:8 
求助:“当x位于1到20之间时,将x的值赋给变量y;如果x不在这个范围内,则保持y的值不变。”为什么我输不出结果来。。
#include <stdio.h>

   int x ,y;

int main(void)
{
  int x =8;

   if((1<x)&&(x>=20))
    {
       y=x;
     }

     printf("\n打印y:",y );




        system("PAUSE");
      return 0;
}

输出的结果是:打印Y:请按任意键继续
 为什么会这样?
搜索更多相关主题的帖子: include system return 
2011-10-25 21:58
dani337
Rank: 1
等 级:新手上路
帖 子:20
专家分:9
注 册:2011-10-25
收藏
得分:0 
回复 楼主 dani337
谢谢。我试了,不过还是一样的结果。不知道哪出了问题,实在找不到。
2011-10-25 22:06
dani337
Rank: 1
等 级:新手上路
帖 子:20
专家分:9
注 册:2011-10-25
收藏
得分:0 
回复 2楼 ppfly
不对啊。这样打印出来的是0,和我的题目对不起来。我x=8,按题目应该打印的是8,而不是0
  而且if应该是((1>x)&&(x<=20))这样啊。。找个事答案里面的。不过答案太简单了。
2011-10-25 22:11
dani337
Rank: 1
等 级:新手上路
帖 子:20
专家分:9
注 册:2011-10-25
收藏
得分:0 
回复 6楼 laznrbfe
y赋值为0的时候,只能输出0;
  
2011-10-25 22:18
dani337
Rank: 1
等 级:新手上路
帖 子:20
专家分:9
注 册:2011-10-25
收藏
得分:0 
回复 8楼 dani337
按你这样编译的时候提示有错误
In file included from C:\DEV-C_~1\Include\windows.h:78,
                 from e:\c\4112练~1.c:2:
C:\DEV-C_~1\Include\windef.h:153: parse error before `#'
C:\DEV-C_~1\Include\windef.h:153: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:154: parse error before `#'
C:\DEV-C_~1\Include\windef.h:154: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:155: parse error before `#'
C:\DEV-C_~1\Include\windef.h:155: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:156: parse error before `#'
C:\DEV-C_~1\Include\windef.h:156: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:157: parse error before `#'
C:\DEV-C_~1\Include\windef.h:157: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:158: parse error before `#'
C:\DEV-C_~1\Include\windef.h:158: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:159: parse error before `#'
C:\DEV-C_~1\Include\windef.h:159: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:160: parse error before `#'
C:\DEV-C_~1\Include\windef.h:160: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:161: parse error before `#'
C:\DEV-C_~1\Include\windef.h:161: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:162: parse error before `#'
C:\DEV-C_~1\Include\windef.h:162: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:163: parse error before `#'
C:\DEV-C_~1\Include\windef.h:163: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:164: parse error before `*'
C:\DEV-C_~1\Include\windef.h:164: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:165: parse error before `#'
C:\DEV-C_~1\Include\windef.h:165: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:166: parse error before `#'
C:\DEV-C_~1\Include\windef.h:166: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:167: parse error before `#'
C:\DEV-C_~1\Include\windef.h:167: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:168: parse error before `HMODULE'
C:\DEV-C_~1\Include\windef.h:168: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:169: parse error before `#'
C:\DEV-C_~1\Include\windef.h:169: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:170: parse error before `#'
C:\DEV-C_~1\Include\windef.h:170: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:171: parse error before `#'
C:\DEV-C_~1\Include\windef.h:171: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:172: parse error before `#'
C:\DEV-C_~1\Include\windef.h:172: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:173: parse error before `#'
C:\DEV-C_~1\Include\windef.h:173: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:174: parse error before `#'
2011-10-25 22:21
dani337
Rank: 1
等 级:新手上路
帖 子:20
专家分:9
注 册:2011-10-25
收藏
得分:0 
回复 9楼 laznrbfe
多谢了哦。。就是你说的这样。哈。终于解决了。。
2011-10-25 22:26
dani337
Rank: 1
等 级:新手上路
帖 子:20
专家分:9
注 册:2011-10-25
收藏
得分:0 
不好意思刚说错了。。是10楼的帮我解决的。。他的这个输出的是对的。。
2011-10-25 22:30
dani337
Rank: 1
等 级:新手上路
帖 子:20
专家分:9
注 册:2011-10-25
收藏
得分:0 
回复 12楼 laznrbfe
谢谢了。。你的那个思路好像也是对的。我等下去试试。不过我是用Dev-C++  编译的。可能#include<windows.h>这个不能用吧。
2011-10-25 22:34
dani337
Rank: 1
等 级:新手上路
帖 子:20
专家分:9
注 册:2011-10-25
收藏
得分:0 
我好像就是 if((1<x)&&(x>=20))
这里写错了。。 if((1<x)&&(<=20))  难怪找半天找不到问题。
2011-10-25 22:37
快速回复:求助:“当x位于1到20之间时,将x的值赋给变量y;如果x不在这个范围内 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017876 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved