主题:谁帮我看看这个程序??????
谁帮我看看这个程序,看出了什么问题???????
#include<stdio.h>
#include <conio.h>
#include <process.h>
#include<stdlib.h>
#include <string.h>
/*duo*/
#define NULL 0
#define LEN sizeof(struct duo_fun)
struct duo_fun
{
float xi;
int zhi;
struct duo_fun *next;
};
struct duo_fun *duo_input()
{
struct duo_fun *head,*p1,*p2;
int n=0;
p1=p2=(struct duo_fun *)malloc(LEN);
scanf("%f,%d",&p1->xi,&p1->zhi);
head=NULL;
while(p2->next!=NULL)
{
n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct duo_fun *)malloc(LEN);
scanf("%f,%d",&p1->xi,&p1->zhi);
if(p1->xi==0 && p1->zhi==0) p2->next=NULL;
}
return head;
}
struct duo_fun *add(struct duo_fun *head1,struct duo_fun *head2)
{
int n=0;
struct duo_fun *p1,*p2,*p0,*head,*p3;
p1=head1;
p2=head2;
p3=p0=head=NULL;
p0=head=((p2->zhi < p1->zhi) ? head2:head1);
do
{
n++;
if(p1->zhi==p2->zhi)
{
p1->xi=p1->xi+p2->xi;
p3=p1;
p1=p1->next;
p2=p2->next;
}
else if(p1->zhi < p2->zhi)
{ p3=p1;p1=p1->next;}
else
{ p3=p2;p2=p2->next; }
if(n>0)
{ p0->next=p3;p0=p3;}
}while(p1!=NULL && p2!=NULL);
if(p1!=NULL) p0->next=p1;
else
p0->next=p2;
return(head);
}
void duo_print(struct duo_fun *head)
{
int n=0;
struct duo_fun *p;
p=head;
if(head!=NULL)
do
{
n++;
if(n==1) printf("%.3fx^%d",p->xi,p->zhi);
else printf("+%.3fx^%d",p->xi,p->zhi);
p=p->next;
} while(p!=NULL);
printf("\n");
}
void duo_add()
{
struct duo_fun *head1,*head2,*result;
printf("................^_^duoxiangshi adding^_^.................\n");
printf("The format: xishu,zhishu \nenter <Enter> to next, end whit 0,0\n");
printf("eg:Input 2,1 2,2 2,5 the result:2x^1+2x^2+2x^5\n");
printf("Input the first A:\n");
head1=duo_input();
printf("A=");
duo_print(head1);
printf("Input the second B:\n");
head2=duo_input();
printf("B=");
duo_print(head2);
result=add(head1,head2);
printf("\nC=A+B=");
duo_print(result);
printf("\n");
/*getch();*/
}
/*fenli*/
void fenli(char *p)
{
char *p1,*p2;
int i,j,n=0;
p2=p;
while(*p2)
{
n=n+1;
if(n==1) p1=p2;
else p1=p2+1;
p2=strchr(p1,' ');
if(!p2) p2=strchr(p1,'\0');
j=p2-p1;
for(i=0;i<j;i++) printf("%c",p1[i]);
printf("\n");
}
}
char *shuru(void)
{
int num=0,word=0;
char c;
int i;
char a[1000],*head;
head=a;
printf("input the characters\n");
gets(a);
printf("the result you input.\n");
for(i=0;a[i]!='\0';i++) putchar(a[i]);
printf("\n");
for(i=0;(c=a[i])!='\0';i++)
if(c==' ') word=0;
else if(word==0)
{
word=1;
num++;
}
printf("There are %d words.\n",num);
return head;
}
void fenli_fun()
{
char *p1;
p1=shuru();
fenli(p1);
/*getch();*/
}
void welcom(void)
{
char c;
printf("**********welcom to here ^_^********\n");
printf("thank you to use soft!\n");
printf("Do you want to continue?(y/n):");
scanf("%c",&c);
getchar();
if(c=='y' || c=='Y') printf("OK\n");
else exit(0);
}
void main()
{
char c;
welcom();
printf("Please input the number you want:\n");
printf("0:exit \n1:dou xiang shi adding \n2:sentence to words \n3:er cha shu device \n");
printf("input:");
c=getchar();
getchar();
printf("\n");
while(c!='0')
{
/*clrscr();*/
switch(c)
{
case '1': duo_add(); break;
case '2': fenli_fun(); break;
case '3': printf("doing...");break;
default: printf("Your input is wrong.\n"); break;
}
printf("continue? input 0 to exit.\n");
c=getchar();
}
}
反正我运行时有问题,就是运行多项式之后有问题。高手们帮我看看吧。谢谢!!!
[em10][em7][em16][em18][em18][em18][em18]
#include<stdio.h>
#include <conio.h>
#include <process.h>
#include<stdlib.h>
#include <string.h>
/*duo*/
#define NULL 0
#define LEN sizeof(struct duo_fun)
struct duo_fun
{
float xi;
int zhi;
struct duo_fun *next;
};
struct duo_fun *duo_input()
{
struct duo_fun *head,*p1,*p2;
int n=0;
p1=p2=(struct duo_fun *)malloc(LEN);
scanf("%f,%d",&p1->xi,&p1->zhi);
head=NULL;
while(p2->next!=NULL)
{
n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct duo_fun *)malloc(LEN);
scanf("%f,%d",&p1->xi,&p1->zhi);
if(p1->xi==0 && p1->zhi==0) p2->next=NULL;
}
return head;
}
struct duo_fun *add(struct duo_fun *head1,struct duo_fun *head2)
{
int n=0;
struct duo_fun *p1,*p2,*p0,*head,*p3;
p1=head1;
p2=head2;
p3=p0=head=NULL;
p0=head=((p2->zhi < p1->zhi) ? head2:head1);
do
{
n++;
if(p1->zhi==p2->zhi)
{
p1->xi=p1->xi+p2->xi;
p3=p1;
p1=p1->next;
p2=p2->next;
}
else if(p1->zhi < p2->zhi)
{ p3=p1;p1=p1->next;}
else
{ p3=p2;p2=p2->next; }
if(n>0)
{ p0->next=p3;p0=p3;}
}while(p1!=NULL && p2!=NULL);
if(p1!=NULL) p0->next=p1;
else
p0->next=p2;
return(head);
}
void duo_print(struct duo_fun *head)
{
int n=0;
struct duo_fun *p;
p=head;
if(head!=NULL)
do
{
n++;
if(n==1) printf("%.3fx^%d",p->xi,p->zhi);
else printf("+%.3fx^%d",p->xi,p->zhi);
p=p->next;
} while(p!=NULL);
printf("\n");
}
void duo_add()
{
struct duo_fun *head1,*head2,*result;
printf("................^_^duoxiangshi adding^_^.................\n");
printf("The format: xishu,zhishu \nenter <Enter> to next, end whit 0,0\n");
printf("eg:Input 2,1 2,2 2,5 the result:2x^1+2x^2+2x^5\n");
printf("Input the first A:\n");
head1=duo_input();
printf("A=");
duo_print(head1);
printf("Input the second B:\n");
head2=duo_input();
printf("B=");
duo_print(head2);
result=add(head1,head2);
printf("\nC=A+B=");
duo_print(result);
printf("\n");
/*getch();*/
}
/*fenli*/
void fenli(char *p)
{
char *p1,*p2;
int i,j,n=0;
p2=p;
while(*p2)
{
n=n+1;
if(n==1) p1=p2;
else p1=p2+1;
p2=strchr(p1,' ');
if(!p2) p2=strchr(p1,'\0');
j=p2-p1;
for(i=0;i<j;i++) printf("%c",p1[i]);
printf("\n");
}
}
char *shuru(void)
{
int num=0,word=0;
char c;
int i;
char a[1000],*head;
head=a;
printf("input the characters\n");
gets(a);
printf("the result you input.\n");
for(i=0;a[i]!='\0';i++) putchar(a[i]);
printf("\n");
for(i=0;(c=a[i])!='\0';i++)
if(c==' ') word=0;
else if(word==0)
{
word=1;
num++;
}
printf("There are %d words.\n",num);
return head;
}
void fenli_fun()
{
char *p1;
p1=shuru();
fenli(p1);
/*getch();*/
}
void welcom(void)
{
char c;
printf("**********welcom to here ^_^********\n");
printf("thank you to use soft!\n");
printf("Do you want to continue?(y/n):");
scanf("%c",&c);
getchar();
if(c=='y' || c=='Y') printf("OK\n");
else exit(0);
}
void main()
{
char c;
welcom();
printf("Please input the number you want:\n");
printf("0:exit \n1:dou xiang shi adding \n2:sentence to words \n3:er cha shu device \n");
printf("input:");
c=getchar();
getchar();
printf("\n");
while(c!='0')
{
/*clrscr();*/
switch(c)
{
case '1': duo_add(); break;
case '2': fenli_fun(); break;
case '3': printf("doing...");break;
default: printf("Your input is wrong.\n"); break;
}
printf("continue? input 0 to exit.\n");
c=getchar();
}
}
反正我运行时有问题,就是运行多项式之后有问题。高手们帮我看看吧。谢谢!!!
[em10][em7][em16][em18][em18][em18][em18]