두 다항식을 입력받아 곱을 구하는건데요. 일단 봐주세용 ㅋ
이루리라
질문 제목 : 두 다항식 입력받아 곱구하기!!질문 요약 :배열을 입력받는것까지는 했는데 polynomial a= 저부분 중가로 안에다가
입력받은 배열을 전부 집어넣고싶습니다!!질문 내용 :
int one, one_for, two, two_for;
char one_cfct[10]; //첫번째 계수 (coefficient)
char two_cfct[10]; //두번째 계수
printf(첫번째 다항식의 갯수를 입력해주세요);
scanf(%d, &one);
for(one_for=0; one_forone; one_for++)
{
printf(계수를 입력해주세요(%d 중 %d), one, one_for);
scanf(%d, one_cfct[one_for]);
}
polynomial a={one, {one_cfct[one_for]}}; //-이부분에서 문제에요!! 위에서 입력받았던 one_cfct의 변수배열 내용을
//전부 집어넣고 싶은데 안되네요!! 예를들어서 one_cfct[10]={3, 2, 5 ,4}까지 입력받았다면
polynomial a={one, {3, 2, 5, 4}};로 되게 하고싶습니다 부탁드려요 t_t
polynomial b={4, {3,1,0,2,1}};
아래는 소스 전문입니다
//두 다항식을 입력받아 다항식의 곱을 구하는
//multpoly()함수 프로그램을 구현하시오.
#include stdio.h
#define max(a,b) ((ab)?a:b)
#define max_degree 50
typedef struct{
int degree;
float coef[max_degree];
}polynomial;
polynomial addpoly(polynomial a, polynomial b)
{
polynomial c;
int a_index=0, b_index=0, c_index=0;
int a_degree=a.degree, b_degree=b.degree;
c.degree=max(a.degree, b.degree);
while(a_index=a.degree && b_index=b.degree){
if(a_degree b_degree){
c.coef[c_index++] = a.coef[a_index++];
a_degree--;
}
else if(a_degree == b_degree){
c.coef[c_index++] = a.coef[a_index++]+b.coef[b_index++];
a_degree--;
b_degree--;
}
else{
c.coef[c_index++] = b.coef[b_index++];
b_degree--;
}
}
return c;
}
void printpoly(polynomial p)
{
int i, degree;
degree=p.degree;
for(i=0; i=p.degree; i++)
printf(%3.0fx^%d, p.coef[i], degree--);
printf(\n);
}
void main()
{
int one, one_for, two, two_for;
char one_cfct[10]; //첫번째 계수 (coefficient)
char two_cfct[10]; //두번째 계수
printf(첫번째 다항식의 갯수를 입력해주세요);
scanf(%d, &one);
for(one_for=0; one_forone; one_for++)
{
printf(계수를 입력해주세요(%d 중 %d), one, one_for);
scanf(%d, one_cfct[one_for]);
}
polynomial a={one, {one_cfct[one_for]}};
polynomial b={4, {3,1,0,2,1}};
polynomial c;
c= addpoly(a,b);
printf(\n a(x)=); printpoly(a);
printf(\n b(x)=); printpoly(b);
printf(\n c(x)=); printpoly(c);
getchar();
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2703038 | 솔루션 빌드를 하고 실행하는거랑 (5) | 홀림길 | 2025-07-28 |
2703014 | void *fuction(int a) 이런 함수 질문좀요 (3) | 박애교 | 2025-07-28 |
2702932 | 기본 구조체 인데 잘 모르겠네요.ㅠㅠ | 한국녀 | 2025-07-27 |
2702877 | DVD대여프로그램인데요~ 도와주세요!! | 하늘 | 2025-07-27 |
2702850 | enum인데 해석이 안됩니다.. (1) | 수국 | 2025-07-26 |
2702822 | 가우스 소거법좀 부탁드립니다. | 큰힘 | 2025-07-26 |
2702797 | system("mode con: .. ); 명령어 vs2005에서는.. (1) | 콩알눈 | 2025-07-26 |
2702775 | % 연산자, / 연산자 관련질문 | 솔잎 | 2025-07-26 |
2702743 | Linux message queue를 이용한 방법에서 msgrcv | 뚜야 | 2025-07-25 |
2702661 | 동적으로 3개씩 할당되는 배열 (7) | 별빛 | 2025-07-25 |
2702638 | 문제해결좀 (1) | 개굴츼 | 2025-07-24 |
2702495 | mfc edit control 공백체크 (4) | 분홍이 | 2025-07-23 |
2702465 | 이 함수호출에서 뭐가 잘못됬죠 ?ㅠ | 미즈 | 2025-07-23 |
2702438 | C언어에서 Addr이 뭔가요? (6) | 밝은빛누리예 | 2025-07-23 |
2702384 | 흠.. 피보나치 수열을... for문으로 만들었는데요....ㅠㅠ;; (1) | 계획자 | 2025-07-22 |
2702354 | c언어 하나더 질문드리겠습니다^^ | 유키 | 2025-07-22 |
2702323 | 배열 최빈값 구하는 소스 좀 갈켜주셈. | PrinceSs | 2025-07-22 |
2702296 | 오류좀 찾아주세요! 스왑함수 (1) | 지우 | 2025-07-21 |
2702232 | 글씨를 검은색, 바탕을 하얀색으로 하는방법좀 가르쳐주세요 !! | 놓아주세요 | 2025-07-21 |
2702205 | for문 중첩ㅠㅠ (2) | 한뎃집 | 2025-07-21 |