게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
본삭금) c언어 (구조체, math.h )질문이요~~!
게시물ID : programmer_7919짧은주소 복사하기
작성자 : 찌빠묵
추천 : 0
조회수 : 1450회
댓글수 : 4개
등록시간 : 2015/01/30 19:48:32
옵션
  • 본인삭제금지
아래 소스로 복소수를 계산하는 프로그램을 만들려고 합니다.
 
아래부분 주석처리한 sqrt함수를 쓰기위해 #include <math.h>를 입력하면
 
error C2011: '_complex' : 'struct' type redefinition  이런 에러가 발생합니다.
 
찾아보기로는 같은 변수를 두번이상 사용 했을때 나타나는 에러라는데 두번 사용 한것은 없구요
 
#include <math.h>를 빼고 sqrt함수도 빼면 잘 실행이 됩니다.
 
왜 에러가 뜨는것이고 어떻게 수정을 하면 좋을지 팁좀 부탁드립니다.
(주석처리한 부분을 사용하려는 이유는 분수의 분모가 0일때 오류를 나타내기 위함입니다.)
 
 
 
/* 복소수의 덧셈, 뺄셈, 곱셈, 나눗셈을 수행하는 함수 */
 
#include <stdio.h>
//#include <math.h>
 
struct complex {
 double real;
 double imag;
};
 
enum kind { addition , subtraction ,multiplication ,division };
 
void calculation (struct complex *p,enum kind selection);
 
int main ()
{
 struct complex A[2];
 enum kind selection;
 struct complex *p;
 p=A;
 printf("연산을 선택하시오 : ");
 scanf("%d",&selection);
 calculation ( p, selection);
 return 0 ;
}
 
void calculation (struct complex *p,enum kind selection)
{
 double value,value_1;
 
 if( selection ==0 )
 {
  printf("(a+bi)+(c+di)\n");
  printf("a,b,c,d를 차례로 입력 하시오 : ");
  scanf("%lf %lf %lf %lf", &p->imag, &p->real, &(p+1)->imag, &(p+1)->real);
  value =(p->imag) + ((p+1)->imag);
  value_1 =(p->real) + ((p+1)->real);
 }
 else if( selection ==1 )
 {
  printf("(a+bi)-(c+di)\n");
  printf("a,b,c,d를 차례로 입력 하시오 : ");
  scanf("%lf %lf %lf %lf", &p->imag, &p->real, &(p+1)->imag, &(p+1)->real);
  value=(p->imag) - ((p+1)->imag);
  value_1=(p->real) - ((p+1)->real);
 }
 else if( selection ==2 )
 {
  printf("(a+bi)*(c+di)\n");
  printf("a,b,c,d를 차례로 입력 하시오 : ");
  scanf("%lf %lf %lf %lf", &p->imag, &p->real, &(p+1)->imag, &(p+1)->real);
  value=(p->imag) * ((p+1)->imag) - (p->real) * ((p+1)->real);
  value_1=(p->imag) * ((p+1)->real) +( p->real) * ((p+1)->imag);
 }
 else if( selection ==3 )
 {
  printf("(a+bi)/(c+di)\n");
  printf("a,b,c,d를 차례로 입력 하시오 : ");
  scanf("%lf %lf %lf %lf", &p->imag, &p->real, &(p+1)->imag, &(p+1)->real);
 
//  if( ((p+1)->imag) + ((p+1)->real) * (sqrt(-1)) == 0) 
//  {printf("오류\n");}
 
  value=((p->imag) * ((p+1)->imag) + (p->real) * ((p+1)->real) )/( ((p+1)->imag) * ((p+1)->imag) + ((p+1)->real) * ((p+1)->real));
  value_1=(( p->real) * ((p+1)->imag) - (p->imag) * ((p+1)->real))/( ((p+1)->imag) * ((p+1)->imag) +((p+1)->real) * ((p+1)->real));
 }
 else
 {printf("오류\n");}
 
 if(selection <=3 && selection >= 0) 
  printf("값 = (%lf)+(%lf)i\n",value,value_1);
}
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호