두 다항식을 입력받아 곱을 구하는건데요. 일단 봐주세용 ㅋ
연체리
질문 제목 : 두 다항식 입력받아 곱구하기!!질문 요약 :배열을 입력받는것까지는 했는데 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();
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |
2691483 | 파일 오픈시 에러 질문드립니다. (2) | 호습다 | 2025-04-14 |
2691450 | [visual c++ 툴]기초 질문 (3) | 해긴 | 2025-04-13 |
2691393 | UNIX 시스템을 사용하려면 어떤 프로그램이 좋을까요? (5) | 든솔 | 2025-04-13 |
2691334 | ㅠㅠ에러 (1) | Loseless | 2025-04-12 |
2691304 | 포인터배열에 대해 질문요 | 달님 | 2025-04-12 |
2691279 | float-정수변환-2진수변환 | 핫블루 | 2025-04-12 |