두 다항식을 입력받아 곱을 구하는건데요. 일단 봐주세용 ㅋ
연체리
질문 제목 : 두 다항식 입력받아 곱구하기!!질문 요약 :배열을 입력받는것까지는 했는데 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();
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700610 | 정말 기초적인 더하기,여백 문제 help | 무슬 | 2025-07-06 |
2700562 | 함수포인터에서요 (7) | 소심한여자 | 2025-07-06 |
2700530 | 전처리문 질문입니다. (1) | 아놀드 | 2025-07-05 |
2700510 | c언어를 어케하면 잘할수 있을까요.. | 연연두 | 2025-07-05 |
2700484 | 두 개가 차이가 뭔지 알려주세요...(소수 찾는 프로그램) (2) | 날위해 | 2025-07-05 |
2700426 | 인터넷 창 띄우는 질문이요 (1) | 정훈 | 2025-07-04 |
2700400 | 원넓이를 계산이요 ㅜㅜ | 천칭자리 | 2025-07-04 |
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |
2700070 | while문 , 3의배수 출력하는 프로그램좀 짜주세욤. | 횃불 | 2025-07-01 |
2700041 | 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? | 헛장사 | 2025-07-01 |
2700012 | 배열// (1) | 전갈자리 | 2025-07-01 |