#include <stdio.h>
struct complex{
double real;
double img;
};
struct complex creat(void);
struct complex* minu(struct complex ,struct complex );
struct complex* power(struct complex ,struct complex );
int main()
{
struct complex com1,com2,*resul;
int i;
//input
com1 = creat();
getchar();
com2 = creat();
getchar();
do{
printf(\"빼기 : 1, 곱하기 : 2\\t\");
scanf(\"%d\",&i);
}while(i!=1 && i!=2);
//output
if(i == 1)
resul = minu(com1,com2);
else
resul = power(com1,com2);
if(resul->img > 0)
printf(\"%.2lf + %.2lfi\\n\",resul->real,resul->img);
else if(resul->img < 0)
printf(\"%.2lf %.2lfi\\n\",resul->real,resul->img);
else
printf(\"%.2lf\\n\",resul->real);
return 0;
}
struct complex creat()
{
struct complex creat;
scanf(\"%lf %lf\",&creat.real,&creat.img);
return creat;
}
struct complex* minu(struct complex t_com1,struct complex t_com2)
{
static struct complex result;
result.real = t_com1.real - t_com2.real;
result.img = t_com1.img - t_com2.img;
return &result;
}
struct complex* power(struct complex t_com1,struct complex t_com2)
{
static struct complex result;
result.real = t_com1.real * t_com2.real - t_com1.img * t_com2.img;
result.img = t_com1.img * t_com2.real + t_com1.real * t_com2.img;
return &result;
}
포인터로도 반환하고, 형도 반환하니 문제 없겠지 ? ㄱ-...
tag 안 쓴거 빼곤, 나름대로 깔끔하다고 자부 ``
static이라니 존나 흠좀무
minu(power(com1,com2),power(com2,com1)) 이거 돌아감?
아 포인터를 안쓰고 포인터 반환을 저렇게 할 줄이야.. 대단
static 말고, 함수가 종료 되는데, 살아 있는 배열 만들 수 잇음 ? 안 그럼 경고창 띠잉 ~ 뜨던데, 참고로 저 static 묻던게, 우리 학교 중간고사 마지막 문제였음 ``
static이라니 존나 흠좀무
돌아감, 경고 0 에러 0, 실행 참값만 쑥쑥 배터냄
동적할당은 살아있는 배열 만들라고 있는거다
static대신 전역변수하면 막장?
디-횽 전에 문자열 관련해서 함수 내부의 동적할당하고 포인터 반환 글 하나 쓰지 않았었어?
아 난독증 -_-...minu(power(com1,com2),power(com2,com1)) <- 이거는 머임 ? 내 소스에 없는건데 -_-;;
클립보드의 인공지능
static은 진짜 흠좆무
결과가 제대로 안 나올거라고. 저건 잘못 쓴거고... com1~4 변수에 값 넣고 minu(*power(&com1,&com2),*power(&com3,&com4)) 이거 하면 값 제대로 안나올걸?
내가 전에 썼던 글은
http://gall.dcinside.com/list.php?id=programming&no=23465
아 물론 글에서처럼 minu, power 1번씩만 쓸거면 문제는 없겠수다...
static이라 덮어쓸수 밖에 없어지는군. malloc 과 free를 찾아보삼
오 내가 하고싶은말을 전부다 디-횽이 써놨네... 주옥같은 글이군