|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
//有哪位同学能告诉我怎么整啊 为什么都是错555555
#include<stdio.h>
#include<stdlib.h>
#define DT sizeof(struct answer)//链表大小后面动态内存
struct answer *creat();//创建链表
void print(struct student *head);//打印链表
struct answer
{
double num;//输入数
char ch;//符号
struct answer *next;//链接下一个链表
};
int n;//计数n 全局变量
void main()
{
struct answer *w,*p;
w = creat();
p = w;
print(p);
printf("\n\n");
system("pause");
}
struct answer creat()
{
struct answer *head;
struct answer *p1,*p2;
p1 = p2 =(struct answer *)malloc(DT);
printf("请输入数和符号:");
scanf("%f %c",&p1->num,&p1->ch);
head = NULL;
n=0;
while((p1->ch)!='=')
{
n++;
if( 1 == n)
{
head = p1;
}
else
{
p2->next = p1;
}
p2 = p1;
p1 =(struct student *)malloc(DT);
scanf("%f %c",&p1->num,&p1->ch);
}
p2->next = NULL;
return head;
}
void print(struct student *head)
{
struct student *p;
printf("\n There are %d records!\n\n",n);
p = head;
if(head)
{
do
{
switch(p->ch)
{
case '+':(p->num) = (p->num) + (p->next->num);
(p->ch) = (p->next->ch);
(p->next) = (p->next->next);
p = head; break;
case '-':(p->num) = (p->num) - (p->next->num);
(p->ch) - (p->next->ch);
(p->next) = (p->next->next);
p = head; break;
}
}while(p);
printf("%f",p->num);
}
} |
|