[1] 質問文
[1.1] 自分が今行いたい事は何か
入力した順番に単項式を出力するようにしたいです。
[1.2] 今何がわからないのか、知りたいのか
どこをいじれば入力した順にできるのかわからずいろいろとやっているができない
ぜひお力を貸してください。
よろしくお願いします。
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
struct mono {
int coef;
int degree_of_x;
struct mono *next;
};
struct mono mend;
struct mono *pmx;
struct mono *poly;
struct mono *pwork;
mend.coef = 0;
mend.degree_of_x = 0;
mend.next = NULL;
poly = &mend;
while (1)
{
pmx = (struct mono *)malloc(sizeof(struct mono));
if (pmx == NULL)
{
printf("No memory!!");
exit(1);
};
printf("Input the coefficient: ");
scanf("%d", &pmx->coef);
if ( pmx->coef == 0) break;
printf("Input the degree: ");
scanf("%d", &pmx->degree_of_x);
pmx->next = poly;
poly = pmx;
};
for (pwork = poly; pwork->next != NULL; pwork = pwork->next)
{
if(pwork->degree_of_x == 0){
printf("%+d", pwork->coef);
}else{
printf("%+dx^{%d}",pwork->coef, pwork->degree_of_x);
}
};
return 0;
}