참고 소스
페이지 정보
본문
#include <stdio.h>
#include <math.h>
#include <conio.h>
//사칙연산
void Sachic_Input(double *a,double *b,char *c);
void Sachic_process(double a,double b,char c);
//이차방정식
void GetABC(double *Find2root_a, double *Find2root_b, double *Find2root_c);
void Process(const double Find2root_a, const double Find2root_b, const double Find2root_c, double *Find2root_D, double *Find2root_x1, double *Find2root_x2);
void Output2(const double Find2root_D, const double Find2root_x1, const double Find2root_x2);
//원의둘레넓이
void GetRadius(double *);
void CalAreaCir(const double , double *, double *);
void Output3(const double ,const double);
void tri_function();
///////////////////////////////////////////////////////////////////////////////////////////////////////
void main(void)
{
int select;
double a=0, b=0;
char c=0;
printf("-----------메뉴-------------\n"); //메뉴 선택창
printf("원하는 연산을 입력하시오. \n");
printf("1.사칙연산.\n");
printf("2.이차방정식.\n");
printf("3.원의넓이,둘레구하기.\n");
printf("4.삼각함수값구하기.\n");
printf("5.종료합니다.\n");
printf("----------------------------\n");
printf("선택 = ");
scanf("%d",&select);
switch(select)
{
case 1: //1번을 선택하였을경우
{
double a,b;
char c;
Sachic_Input(&a,&b,&c); // 포인터라 ... & 붙여야함.
Sachic_process(a,b,c);
break;
}
case 2: //2번을 선택하였을경우
{
printf("이차방정식 프로그램입니다.\n");
printf("Ax^2+B*x+C =0 \n");
double Find2root_a, Find2root_b, Find2root_c, Find2root_D, Find2root_x1, Find2root_x2; //변수설정
GetABC(&Find2root_a, &Find2root_b, &Find2root_c); //함수호출
Process(Find2root_a, Find2root_b, Find2root_c, &Find2root_D, &Find2root_x1, &Find2root_x2); //함수호출
Output2(Find2root_D, Find2root_x1, Find2root_x2); //함수호출
break;
}
case 3:
{
double AreaCir_r;// r-반지름
double AreaCir_Area, AreaCir_Cir;// Area-면적 Cir-둘레
GetRadius(&AreaCir_r); //함수호출
CalAreaCir(AreaCir_r,&AreaCir_Area,&AreaCir_Cir); //함수호출
Output3(AreaCir_Area,AreaCir_Cir); //함수호출
break;
}
case 4:
{
tri_function();
break;
}
case 5:
{
printf("종료합니다.\n");
break;
}
default: // 첫번째 선택이 잘못되었을때.
printf("잘못입력하셨습니다.\n");
break;
}
getch();
}
//사칙연산
void Sachic_Input(double *a,double *b,char *c)
{
printf("사칙연산 프로그램입니다.\n");
printf("ex)300 + 200\n");
printf("입력하시오.\n");
scanf("%lf %c %lf", a,c,b);
}
void Sachic_process(double a,double b,char c)
{
switch(c)
{
case '+':
printf("%lf\n", a+b);
break;
case '-':
printf("%lf\n", a-b);
break;
case '*':
printf("%lf\n", a*b);
break;
case '/':
printf("%lf\n", a/b);
break;
default:
printf("잘못 입력하셨습니다.\n");
break;
}
}
//이차방정식.
void GetABC(double *Find2root_a, double *Find2root_b, double *Find2root_c)
{
while(1){
printf("(A는 0이아닌 실수)\n A = ");
scanf("%lf",Find2root_a);
if(*Find2root_a!=0) //a= 0일경우에는 다시입력
{
break;
}
}
printf("b = ");
scanf("%lf",Find2root_b); //B 대입
printf("c = ");
scanf("%lf",Find2root_c); //C 대입
}
//계산과정
void Process(const double Find2root_a, const double Find2root_b, const double Find2root_c, double *Find2root_D, double *Find2root_x1, double *Find2root_x2)
{
*Find2root_D = Find2root_b*Find2root_b - 4*Find2root_a*Find2root_c;
if( *Find2root_D > 0) //판별식이 양수일경우
{
*Find2root_x1= (-Find2root_b + sqrt(*Find2root_D))/(2*Find2root_a); // 근 계산
*Find2root_x2= (-Find2root_b - sqrt(*Find2root_D))/(2*Find2root_a);
printf("두 실근을 가지고 ");
}
else if( *Find2root_D ==0) //판별식이 0일경우
{
*Find2root_x1= (-Find2root_b + sqrt(*Find2root_D))/(2*Find2root_a); // 근 계산
*Find2root_x2= (-Find2root_b - sqrt(*Find2root_D))/(2*Find2root_a);
printf("중근을 가지고 ");
}
else //판별식이 음수일경우
{
*Find2root_x1= (-Find2root_b)/(2*Find2root_a); // 근 계산
*Find2root_x2= sqrt(-(*Find2root_D));
printf("두 허근을 가지고 ");
}
}
void Output2(const double Find2root_D, const double Find2root_x1, const double Find2root_x2) //출력함수
{
if(Find2root_D>0)
{
printf("근 x1=%.3lf x2=%.3lf 입니다.\n",Find2root_x1, Find2root_x2);
}
else if(Find2root_D==0)
{
printf("근은 %.3lf 입니다.\n",Find2root_x1);
}
else
{
printf("근은 x1=%.3lf+%.3lfi x2=%.3lf-%.3lfi\n",Find2root_x1,Find2root_x2,Find2root_x1,Find2root_x2);
}
}
//원의 둘레 넓이 프로그램함수
void GetRadius(double *AreaCir_r) //반지름 입력함수.
{
printf("반지름을 입력하시오\n 입력 =");
scanf("%lf",AreaCir_r);
}
void CalAreaCir(const double AreaCir_r, double *AreaCir_Area, double *AreaCir_Cir) //계산함수.
{
double Pi=4*atan(1.0);
*AreaCir_Area=Pi*AreaCir_r*AreaCir_r;
*AreaCir_Cir=2*Pi*AreaCir_r;
}
void Output3(const double AreaCir_Area,const double AreaCir_Cir) //출력함수.
{
printf("원의 면적은 %lf\n",AreaCir_Area);
printf("원의 둘레는 %lf입니다.\n",AreaCir_Cir);
}
void tri_function()
{
double gak=0,result=0,rad=0;
int sel=0;
double Pi=4*atan(1.0); //정확한 Pi 값계산.
printf("삼각함수 계산 프로그램입니다.\n");
printf("원하는 삼각함수를 고르시오.\n");
printf("1.sin 2.cos 3.tan\n");
scanf("%d",&sel);
if(sel==1) //sin 계산
{
printf("사인입니다.\n");
printf("각도를 입력하시오.\n");
scanf("%lf",&gak); // double 형이라 %lf 로 수정
rad = gak*Pi/180; //라디안으로 바꾸는 과정
result = sin(rad);
printf("결과는 %f입니다.\n",result);
}
else if(sel==2) //cos 계산
{
printf("코사인입니다.\n");
printf("각도를 입력하시오.\n");
scanf("%lf",&gak);
rad = gak*Pi/180; //라디안으로 바꾸는 과정
result = cos(rad);
printf("결과는 %f입니다.\n",result);
}
else if(sel==3) //tan 계산
{
printf("탄젠트입니다.\n");
printf("각도를 입력하시오.\n");
scanf("%lf",&gak);
rad = gak*Pi/180; //라디안으로 바꾸는 과정
result = tan(rad);
printf("결과는 %f입니다.\n",result);
}
else // 잘못입력하였을경우
{
printf("잘못입력하셨습니다.\n");
}
}
원본 : 지식
#include <math.h>
#include <conio.h>
//사칙연산
void Sachic_Input(double *a,double *b,char *c);
void Sachic_process(double a,double b,char c);
//이차방정식
void GetABC(double *Find2root_a, double *Find2root_b, double *Find2root_c);
void Process(const double Find2root_a, const double Find2root_b, const double Find2root_c, double *Find2root_D, double *Find2root_x1, double *Find2root_x2);
void Output2(const double Find2root_D, const double Find2root_x1, const double Find2root_x2);
//원의둘레넓이
void GetRadius(double *);
void CalAreaCir(const double , double *, double *);
void Output3(const double ,const double);
void tri_function();
///////////////////////////////////////////////////////////////////////////////////////////////////////
void main(void)
{
int select;
double a=0, b=0;
char c=0;
printf("-----------메뉴-------------\n"); //메뉴 선택창
printf("원하는 연산을 입력하시오. \n");
printf("1.사칙연산.\n");
printf("2.이차방정식.\n");
printf("3.원의넓이,둘레구하기.\n");
printf("4.삼각함수값구하기.\n");
printf("5.종료합니다.\n");
printf("----------------------------\n");
printf("선택 = ");
scanf("%d",&select);
switch(select)
{
case 1: //1번을 선택하였을경우
{
double a,b;
char c;
Sachic_Input(&a,&b,&c); // 포인터라 ... & 붙여야함.
Sachic_process(a,b,c);
break;
}
case 2: //2번을 선택하였을경우
{
printf("이차방정식 프로그램입니다.\n");
printf("Ax^2+B*x+C =0 \n");
double Find2root_a, Find2root_b, Find2root_c, Find2root_D, Find2root_x1, Find2root_x2; //변수설정
GetABC(&Find2root_a, &Find2root_b, &Find2root_c); //함수호출
Process(Find2root_a, Find2root_b, Find2root_c, &Find2root_D, &Find2root_x1, &Find2root_x2); //함수호출
Output2(Find2root_D, Find2root_x1, Find2root_x2); //함수호출
break;
}
case 3:
{
double AreaCir_r;// r-반지름
double AreaCir_Area, AreaCir_Cir;// Area-면적 Cir-둘레
GetRadius(&AreaCir_r); //함수호출
CalAreaCir(AreaCir_r,&AreaCir_Area,&AreaCir_Cir); //함수호출
Output3(AreaCir_Area,AreaCir_Cir); //함수호출
break;
}
case 4:
{
tri_function();
break;
}
case 5:
{
printf("종료합니다.\n");
break;
}
default: // 첫번째 선택이 잘못되었을때.
printf("잘못입력하셨습니다.\n");
break;
}
getch();
}
//사칙연산
void Sachic_Input(double *a,double *b,char *c)
{
printf("사칙연산 프로그램입니다.\n");
printf("ex)300 + 200\n");
printf("입력하시오.\n");
scanf("%lf %c %lf", a,c,b);
}
void Sachic_process(double a,double b,char c)
{
switch(c)
{
case '+':
printf("%lf\n", a+b);
break;
case '-':
printf("%lf\n", a-b);
break;
case '*':
printf("%lf\n", a*b);
break;
case '/':
printf("%lf\n", a/b);
break;
default:
printf("잘못 입력하셨습니다.\n");
break;
}
}
//이차방정식.
void GetABC(double *Find2root_a, double *Find2root_b, double *Find2root_c)
{
while(1){
printf("(A는 0이아닌 실수)\n A = ");
scanf("%lf",Find2root_a);
if(*Find2root_a!=0) //a= 0일경우에는 다시입력
{
break;
}
}
printf("b = ");
scanf("%lf",Find2root_b); //B 대입
printf("c = ");
scanf("%lf",Find2root_c); //C 대입
}
//계산과정
void Process(const double Find2root_a, const double Find2root_b, const double Find2root_c, double *Find2root_D, double *Find2root_x1, double *Find2root_x2)
{
*Find2root_D = Find2root_b*Find2root_b - 4*Find2root_a*Find2root_c;
if( *Find2root_D > 0) //판별식이 양수일경우
{
*Find2root_x1= (-Find2root_b + sqrt(*Find2root_D))/(2*Find2root_a); // 근 계산
*Find2root_x2= (-Find2root_b - sqrt(*Find2root_D))/(2*Find2root_a);
printf("두 실근을 가지고 ");
}
else if( *Find2root_D ==0) //판별식이 0일경우
{
*Find2root_x1= (-Find2root_b + sqrt(*Find2root_D))/(2*Find2root_a); // 근 계산
*Find2root_x2= (-Find2root_b - sqrt(*Find2root_D))/(2*Find2root_a);
printf("중근을 가지고 ");
}
else //판별식이 음수일경우
{
*Find2root_x1= (-Find2root_b)/(2*Find2root_a); // 근 계산
*Find2root_x2= sqrt(-(*Find2root_D));
printf("두 허근을 가지고 ");
}
}
void Output2(const double Find2root_D, const double Find2root_x1, const double Find2root_x2) //출력함수
{
if(Find2root_D>0)
{
printf("근 x1=%.3lf x2=%.3lf 입니다.\n",Find2root_x1, Find2root_x2);
}
else if(Find2root_D==0)
{
printf("근은 %.3lf 입니다.\n",Find2root_x1);
}
else
{
printf("근은 x1=%.3lf+%.3lfi x2=%.3lf-%.3lfi\n",Find2root_x1,Find2root_x2,Find2root_x1,Find2root_x2);
}
}
//원의 둘레 넓이 프로그램함수
void GetRadius(double *AreaCir_r) //반지름 입력함수.
{
printf("반지름을 입력하시오\n 입력 =");
scanf("%lf",AreaCir_r);
}
void CalAreaCir(const double AreaCir_r, double *AreaCir_Area, double *AreaCir_Cir) //계산함수.
{
double Pi=4*atan(1.0);
*AreaCir_Area=Pi*AreaCir_r*AreaCir_r;
*AreaCir_Cir=2*Pi*AreaCir_r;
}
void Output3(const double AreaCir_Area,const double AreaCir_Cir) //출력함수.
{
printf("원의 면적은 %lf\n",AreaCir_Area);
printf("원의 둘레는 %lf입니다.\n",AreaCir_Cir);
}
void tri_function()
{
double gak=0,result=0,rad=0;
int sel=0;
double Pi=4*atan(1.0); //정확한 Pi 값계산.
printf("삼각함수 계산 프로그램입니다.\n");
printf("원하는 삼각함수를 고르시오.\n");
printf("1.sin 2.cos 3.tan\n");
scanf("%d",&sel);
if(sel==1) //sin 계산
{
printf("사인입니다.\n");
printf("각도를 입력하시오.\n");
scanf("%lf",&gak); // double 형이라 %lf 로 수정
rad = gak*Pi/180; //라디안으로 바꾸는 과정
result = sin(rad);
printf("결과는 %f입니다.\n",result);
}
else if(sel==2) //cos 계산
{
printf("코사인입니다.\n");
printf("각도를 입력하시오.\n");
scanf("%lf",&gak);
rad = gak*Pi/180; //라디안으로 바꾸는 과정
result = cos(rad);
printf("결과는 %f입니다.\n",result);
}
else if(sel==3) //tan 계산
{
printf("탄젠트입니다.\n");
printf("각도를 입력하시오.\n");
scanf("%lf",&gak);
rad = gak*Pi/180; //라디안으로 바꾸는 과정
result = tan(rad);
printf("결과는 %f입니다.\n",result);
}
else // 잘못입력하였을경우
{
printf("잘못입력하셨습니다.\n");
}
}
원본 : 지식
댓글목록
등록된 댓글이 없습니다.