
C语言是在是入不了门了~这个程序是书上的,但是结果却不是我想要的,求高手开导,怎么入门····
#include<stdio.h>inthcf,lcd;intmain(){voidhcf(int,int);voidlcd(int,int);intu,v;scanf(...
#include<stdio.h>int hcf,lcd;
int main()
{
void hcf(int,int);
void lcd(int,int);
int u,v;
scanf("%d,%d",&u,&v);
hcf(u,v);
lcd(u,v);
printf("h.c.f=%d\n",hcf);
printf("l.c.d=%d\n",lcd);
return 0;
}
void hcf(int u,int v){
int t,r;
if(v>u)
{
t=u;u=v;v=t;}
while((r=u%v)!=0)
{
u=v;
v=r;
}
hcf=v;
}
void lcd(int u,int v){
lcd=u*v/hcf;
}
这算法是书上的,我的和他字母不一样~但结果却不是最大公约数和最小公倍数,当时被调剂到这个专业就很难受,现在C语言什么题都成功不了,如何入门,十分苦恼,求高手开导!!!!! 展开
int main()
{
void hcf(int,int);
void lcd(int,int);
int u,v;
scanf("%d,%d",&u,&v);
hcf(u,v);
lcd(u,v);
printf("h.c.f=%d\n",hcf);
printf("l.c.d=%d\n",lcd);
return 0;
}
void hcf(int u,int v){
int t,r;
if(v>u)
{
t=u;u=v;v=t;}
while((r=u%v)!=0)
{
u=v;
v=r;
}
hcf=v;
}
void lcd(int u,int v){
lcd=u*v/hcf;
}
这算法是书上的,我的和他字母不一样~但结果却不是最大公约数和最小公倍数,当时被调剂到这个专业就很难受,现在C语言什么题都成功不了,如何入门,十分苦恼,求高手开导!!!!! 展开
展开全部
#include<stdio.h>
int h,l;
int main(){
void hcf(int,int);
void lcd(int,int); int u,v;
scanf("%d,%d",&u,&v);
hcf(u,v);
lcd(u,v);
printf("h.c.f=%d\n",h);
printf("l.c.d=%d\n",l); return 0;}
void hcf(int u,int v)
{ int t,r; if(v>u)
{ t=u;u=v;v=t;}
while((r=u%v)!=0)
{ u=v; v=r; }
h=v;}
void lcd(int u,int v){ l=u*v/h;}
函数名和变量名重复了
这样就可以运行了
int h,l;
int main(){
void hcf(int,int);
void lcd(int,int); int u,v;
scanf("%d,%d",&u,&v);
hcf(u,v);
lcd(u,v);
printf("h.c.f=%d\n",h);
printf("l.c.d=%d\n",l); return 0;}
void hcf(int u,int v)
{ int t,r; if(v>u)
{ t=u;u=v;v=t;}
while((r=u%v)!=0)
{ u=v; v=r; }
h=v;}
void lcd(int u,int v){ l=u*v/h;}
函数名和变量名重复了
这样就可以运行了
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你定义的全局变量跟函数名 同名了,编译器不知道用那俩名字的时候调用哪一个了,编译器会很迷惑的。。。书上估计变量名用了大写,函数名用了小写。
另外你的函数有点累赘,找最大公约数只需要这么写:
void hcf(int u,int v){
int t,r;
while((r=u%v)!=0)
{
u=v;
v=r;
}
hcf=v;
}
另外你的函数有点累赘,找最大公约数只需要这么写:
void hcf(int u,int v){
int t,r;
while((r=u%v)!=0)
{
u=v;
v=r;
}
hcf=v;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-12-01
展开全部
楼主学的书有问题。
追问
那个大小写是我复制错了,但是把大小写改过来程序运行错误。这是清华大学出版社的C程序设计第四版第7章第1道习题。。我们的课本
追答
果然是误人子弟的谭老先生编的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |