📄 polyadd.c
字号:
/* file name: polyadd.c */
/* 多项式相加--使用降序排列输入两个格式为ax^b的多项式相加 */
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void input(struct poly *, struct poly *, struct poly *); /* 输入函数 */
void poly_add(void); /* 多项式相加函数 */
void show_ans(void); /* 显示多项式相加结果函数 */
void display_func(struct poly *, struct poly *);
struct poly {
int coef; /* 多项式系数 */
int exp; /* 多项式指数 */
struct poly *next;
};
struct poly *ptr, *head1, *head2, *this_n1, *this_n2, *prev1, *prev2, *eq_h1, *eq_h2, *ans_h;
void main(void)
{
head1=(struct poly *) malloc(sizeof(struct poly));
head1->next = NULL;
head2=(struct poly *) malloc(sizeof(struct poly));
head2->next = NULL;
printf("****************************************\n");
printf(" -- Polynomial add using format ax^b --\n");
printf("****************************************\n");
printf("Please enter the first equation\n ");
input(prev1, head1, this_n1);
printf("Please enter the second equation\n ");
input(prev2, head2, this_n2);
poly_add();
show_ans();
}
void input(struct poly *prev, struct poly *head, struct poly *this_n)
{
int count=0;
char temp_coef[4], temp_exp[4];
do
{
ptr = (struct poly *) malloc(sizeof(struct poly));
ptr->next = NULL;
/* 取得输入数据 */
printf(" coefficient : ");
gets(temp_coef);
printf(" exponential : ");
gets(temp_exp);
if (atoi(temp_coef) != -1 && atoi(temp_exp) != -1){
ptr->coef = atoi(temp_coef);
ptr->exp = atoi(temp_exp);
}
else{
break;
}
//插入资料
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -