求高手改程序,谢谢

kelehai 2006-03-11 12:49:57
#define NULL 0
#include <stdio.h>
#include <stdlib.h>
struct node
{
int coej;
int exp;
struct node *next;
};
void main()
{
int coej,exp;
char cont;
struct node *list,*p,*p2,*h;
list=p=(struct node *) malloc(sizeof(struct node));
scanf("%d",&coej);
printf("继续?");
fflush(stdin);
cont=getchar();
while (cont=='y')
{
p2=p;
p=(struct node *) malloc(sizeof(struct node));
scanf("%d",&exp);
p2->next=p;
printf("继续?");
fflush(stdin);
cont=getchar();
}
p->next=NULL;
}
void printf(struct node *h);
{
struct node *p;
p=h; while (p)
{
if (p->coej>0)
printf("+");
else
printf("-");
}
printf("%dx^%d",p->coej,p->exp);
p=p->next;
}
main()
{
struct node *list;
list=creat();
print(list);
}
...全文
215 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangmuqq88 2006-03-12
  • 打赏
  • 举报
回复
欢迎加群20641933,欢迎大家共同交流.提高!(不怕不会,就怕不学.)
wangmuqq88 2006-03-12
  • 打赏
  • 举报
回复
欢迎加群20641933,欢迎大家共同交流.提高!(不怕不会,就怕不学.)
patrick84 2006-03-12
  • 打赏
  • 举报
回复
有两个MAIN函数???
XPR 2006-03-12
  • 打赏
  • 举报
回复
没有说清楚!!!
需求不明确呀!
kelehai 2006-03-11
  • 打赏
  • 举报
回复



#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define NULL 0
struct node
{
int coef;
int exp1;
struct node *next;
};
struct node *create()
{
char cont;
struct node *list,*p,*p2;
list=p=(struct node *) malloc(sizeof(struct node));
printf("继续?");
fflush(stdin);
cont=getchar();
while (cont=='y'||cont=='Y')
{
p2=p;
p=(struct node *) malloc(sizeof(struct node));
scanf("%d",&p->coef);
scanf("%d",&p->exp1);
p2->next=p;

printf("继续?");
fflush(stdin);
cont=getchar();
}
p->next=NULL;
return(list);
};

void print(struct node *list)
{
struct node *p;
p=list->next;
while (p)
{
printf("%dx^%d",p->coef,p->exp1);
p=p->next;
}
}

void main()
{ int c;
struct node *list;
list=create();
print(list);
scanf("%d",&c);
}


这是正确的程序,意图是输入几个数字,然后以方程的形式输出
kelehai 2006-03-11
  • 打赏
  • 举报
回复
编译没有问题但是不能输出
kelehai 2006-03-11
  • 打赏
  • 举报
回复
就是输入连表并且输出,谢谢各位阿
我啃 2006-03-11
  • 打赏
  • 举报
回复
大概是这样的,……大野兽,分配内存不FREE,野兽行经。
楼主说明干什么用!
dengyiwolf 2006-03-11
  • 打赏
  • 举报
回复
用意,大约是这样
新建一个键表后,且输出这个键表

在一个程序中不能有两个入口
Dugowe 2006-03-11
  • 打赏
  • 举报
回复
不明白 两个main()已经让我无奈了

很想知道 这段代码是干嘛的。。。
请楼主说明
lbing7 2006-03-11
  • 打赏
  • 举报
回复
嘿嘿

我也想看看哪位高手把两个MAIN给调出来!在同一个文件里,不注释掉
goodluckyxl 2006-03-11
  • 打赏
  • 举报
回复
晕 两个入口
duduhaha 2006-03-11
  • 打赏
  • 举报
回复
都不说清自己要干啥?怎么改啊?给你改成能运行的了.
#define NULL 0
#include <stdio.h>
#include <stdlib.h>
struct node
{
int coej;
int exp;
struct node *next;
};

struct node * creat()
{
char cont;
struct node *list,*p,*p2,*h;
list=p=(struct node *) malloc(sizeof(struct node));
scanf("%d",&(p->coej));
printf("继续?");
fflush(stdin);
cont=getchar();
while (cont=='y')
{
p2=p;
p=(struct node *) malloc(sizeof(struct node));
scanf("%d",&(p->exp));
p2->next=p;
printf("继续?");
fflush(stdin);
cont=getchar();
}
p->next=NULL;
return list;
}
void print(struct node *h)
{
struct node *p;
p=h;
while (p)
{
if (p->coej>0)
printf("+");
else
printf("-");
p = p->next;
}


}
int main(void)
{
struct node *list;
list=creat();
print(list);
return 0;
}


69,368

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧