//15X^11 + 13X^6 + 7X^2 + 6X + 4와 14X ^ 13 + 11X ^ 11 + 10X ^ 10 + 5X + 1 을 더하세용
struct homework1 {
int num;
int square;
};
int main(void) {
struct homework1 homework1[4] = { {15,11}, {13, 6}, {7,2}, {1, 4} };
struct homework1 homework2[4] = { {14,13}, {11, 11}, {10,10}, {5, 1} };
int index1 = 0;
int index2 = 0;
while (1) {
if (index1 == 3 && index2 == 3) {
break;
}
if (homework1[index1].square < homework2[index2].square) {
printf("%dX^%d + ", homework2[index2].num, homework2[index2].square);
index2++;
}
else if (homework1[index1].square > homework2[index2].square) {
printf("%dX^%d + ", homework1[index1].num, homework1[index1].square);
index1++;
}
else {
printf("%dX^%d + ", (homework1[index1].num + homework2[index2].num), homework1[index1].square);
index1++;
index2++;
}
}
}
'Data Structure > 구조체 사용' 카테고리의 다른 글
희소행렬의 표현 (0) | 2020.02.27 |
---|