| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 996 人关注过本帖
标题:[求助]巨大的郁闷 大家帮忙看看!!!
只看楼主 加入收藏
Rank: 1
等 级:新手上路
帖 子:255
专家分:0
注 册:2005-4-25
收藏
 问题点数:0 回复次数:16 
[求助]巨大的郁闷 大家帮忙看看!!!

#include<stdio.h> #include "math.h" f(int a) {int b[3],i,x=a,y=x,k; printf("%d\n",x); i=sqrt(a); if (i*i==a)for (i=1;a>0;i++){b[i]=a%10;a/=10;} else return 0; for (i=2;i--;) for (k=i;k<=2;k++)if(b[i+1]==b[k+2]){printf("%d\n",x);return 1;} return 0;}

int fact(int a) {int i,k=0; for (i=101;i<=a;i++)k+=f(i); printf("%d",k);}

main () {int n; scanf("%d",&n); fact(n); getch(); }

这是怎么回事? 为什么2次输出X的值不同 第一个printf等于a的初值 第二个printf则不等了 而第二个printf处换成Y就等于最初的a了   明明2次printf之间并没有改变过x的值

[此贴子已经被作者于2005-4-28 20:54:04编辑过]

搜索更多相关主题的帖子: include return 
2005-04-28 20:36
Knocker
Rank: 8Rank: 8
等 级:贵宾
威 望:47
帖 子:10454
专家分:603
注 册:2004-6-1
收藏
得分:0 
int b[3]

if (i*i==a)for (i=1;a&gt;0;i++){b[i]=a%10;a/=10;}


这两句是问题所在,改变了x的值,为什么自己想吧。

九洲方除百尺冰,映秀又遭蛮牛耕。汽笛嘶鸣国旗半,哀伤尽处是重生。     -老K
治国就是治吏。礼义廉耻,国之四维。四维不张,国之不国。   -毛泽东
2005-04-28 22:59
Rank: 1
等 级:新手上路
帖 子:255
专家分:0
注 册:2005-4-25
收藏
得分:0 
唉唉是这样啊 数组这一章还没学呢 先放一放吧 谢谢楼上了 学到数组我再把这题揪出来想

/bbs/showimg.asp?BoardID=5&filename=2005-4/2005427111228529.jpg" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=5&filename=2005-4/2005427111228529.jpg');}" onmousewheel="return imgzoom(this);" alt="" /> 欢迎加入C语言QQ群698156 我们都是菜鸟乃至新手 坚信有一天定能展翅高飞 因为有着努力的决心 衷心盼望你的到来 让我们一起进步
2005-04-29 10:17
牛虻
Rank: 1
等 级:新手上路
威 望:1
帖 子:472
专家分:0
注 册:2004-10-1
收藏
得分:0 
以下是引用在2005-4-29 10:17:21的发言: 唉唉是这样啊 数组这一章还没学呢 先放一放吧 谢谢楼上了 学到数组我再把这题揪出来想
这个和数组没关系,因为你在定义x变量时就对x进行赋值为a,即把a的地址给了x,所以一改变a,x也就改变了。否则你这样定义int x;x=a;

[此贴子已经被作者于2005-4-29 10:26:11编辑过]


土冒
2005-04-29 10:23
Rank: 1
等 级:新手上路
帖 子:255
专家分:0
注 册:2005-4-25
收藏
得分:0 
以下是引用牛虻在2005-4-29 10:23:51的发言: 这个和数组没关系,因为你在定义x变量时就对x进行赋值为a,即把a的地址给了x,所以一改变a,x也就改变了。否则你这样定义int x;x=a;
嗯 那我在定义y的时候把x的地址给了y 那为什么改变了a,x也就改变了,但y却没有改变,因为第个printf处改为y就可以输出a的初值

/bbs/showimg.asp?BoardID=5&filename=2005-4/2005427111228529.jpg" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=5&filename=2005-4/2005427111228529.jpg');}" onmousewheel="return imgzoom(this);" alt="" /> 欢迎加入C语言QQ群698156 我们都是菜鸟乃至新手 坚信有一天定能展翅高飞 因为有着努力的决心 衷心盼望你的到来 让我们一起进步
2005-04-29 10:40
牛虻
Rank: 1
等 级:新手上路
威 望:1
帖 子:472
专家分:0
注 册:2004-10-1
收藏
得分:0 
以下是引用在2005-4-29 10:40:58的发言: 嗯 那我在定义y的时候把x的地址给了y 那为什么改变了a,x也就改变了,但y却没有改变,因为第个printf处改为y就可以输出a的初值
o

[此贴子已经被作者于2005-4-29 11:03:06编辑过]


土冒
2005-04-29 10:58
Rank: 1
等 级:新手上路
帖 子:255
专家分:0
注 册:2005-4-25
收藏
得分:0 
改啦 int x,y=x=a;一样的 第二个printf用X就出错 用Y没事

/bbs/showimg.asp?BoardID=5&filename=2005-4/2005427111228529.jpg" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=5&filename=2005-4/2005427111228529.jpg');}" onmousewheel="return imgzoom(this);" alt="" /> 欢迎加入C语言QQ群698156 我们都是菜鸟乃至新手 坚信有一天定能展翅高飞 因为有着努力的决心 衷心盼望你的到来 让我们一起进步
2005-04-29 11:05
牛虻
Rank: 1
等 级:新手上路
威 望:1
帖 子:472
专家分:0
注 册:2004-10-1
收藏
得分:0 
可否贴出你的运行结果

土冒
2005-04-29 11:08
Rank: 1
等 级:新手上路
帖 子:255
专家分:0
注 册:2005-4-25
收藏
得分:0 
这题是求有2位以上相同位数的101至N(n&lt;1000)的完全平方数

按第一帖运行 输入121
121
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
1
1


将第二个printf处的x改为y

再输入121
121
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
121
1

/bbs/showimg.asp?BoardID=5&filename=2005-4/2005427111228529.jpg" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=5&filename=2005-4/2005427111228529.jpg');}" onmousewheel="return imgzoom(this);" alt="" /> 欢迎加入C语言QQ群698156 我们都是菜鸟乃至新手 坚信有一天定能展翅高飞 因为有着努力的决心 衷心盼望你的到来 让我们一起进步
2005-04-29 11:20
牛虻
Rank: 1
等 级:新手上路
威 望:1
帖 子:472
专家分:0
注 册:2004-10-1
收藏
得分:0 
我的运行结果是,第一个和第二个都一样都没变
你单独运行一下f()函数看看
吃饭鸟,等下过来

[此贴子已经被作者于2005-4-29 11:25:23编辑过]



土冒
2005-04-29 11:22
快速回复:[求助]巨大的郁闷 大家帮忙看看!!!
数据加载中...
 
   



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

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