두 다항식을 입력받아 곱을 구하는건데요. 일단 봐주세용 ㅋ
이루리라
질문 제목 : 두 다항식 입력받아 곱구하기!!질문 요약 :배열을 입력받는것까지는 했는데 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();
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2701130 | 중적분문제입니다. 적분구간에 변수가 들어갈순 없나요??ㅡㅜ | 풀큰 | 2025-07-11 |
2701098 | 난수에 질문드립니다. | 큰뫼 | 2025-07-11 |
2701070 | 또다른 시험문제 질문올립니다 | 채련 | 2025-07-10 |
2701042 | 뭐가 잘못된건지 잘 모르겠습니다.;; | 지은 | 2025-07-10 |
2700986 | 뭐가 잘못된건지좀 봐주세요. | 우주 | 2025-07-10 |
2700932 | 도와주세요 ㅠㅠ 모르겟어요 ㅠ | 유희 | 2025-07-09 |
2700900 | 반복문 도움요청..!!합니다. (1) | 두힘 | 2025-07-09 |
2700875 | (유효성검사)프로그램 짜는데 질문이 잇습니다. | 휑하니 | 2025-07-09 |
2700852 | 링크드 리스트 구현시 malloc 관련 에러 입니다. | 삐용삐용 | 2025-07-08 |
2700828 | 7/4 와 7/4.0 의 차이 | 발랄한그1녀 | 2025-07-08 |
2700771 | 아스키값 질문입니다. (+추가 임베디드 다른것도!) (3) | 찰스 | 2025-07-08 |
2700746 | 코드 오류 질문드립니다 | 차분 | 2025-07-07 |
2700721 | 배열 프로그래밍 입니다. (1) | 크나 | 2025-07-07 |
2700695 | 간단한 메모장 구현을 할려고 하는데요 (9) | 늘솜 | 2025-07-07 |
2700668 | c언어 질문입니다. 도와주세요~ (3) | 가자 | 2025-07-07 |
2700639 | 한글입력받아서 ㄱㄴㄷ순서대로출력하는법좀 | 두빛나래 | 2025-07-06 |
2700610 | 정말 기초적인 더하기,여백 문제 help | 무슬 | 2025-07-06 |
2700562 | 함수포인터에서요 (7) | 소심한여자 | 2025-07-06 |
2700530 | 전처리문 질문입니다. (1) | 아놀드 | 2025-07-05 |
2700510 | c언어를 어케하면 잘할수 있을까요.. | 연연두 | 2025-07-05 |