Skip to content
Snippets Groups Projects
Commit b70f0272 authored by 이소현's avatar 이소현
Browse files

lec07

parent ce1c9c98
Branches master
No related tags found
No related merge requests found
#include<stdio.h>
void add(int *a, int *b, int *c)
{ *c = *a + *b;}
void sub(int *a, int *b, int *c)
{ *c = *a - *b;}
void div(int *a, int *b, int *c)
{ *c = (*a) / (*b); }
void mul(int *a, int *b, int *c)
{ *c = (*a) * (*b); }
int main()
{
int a = 100;
int b = 200;
int c = 9999;
char ch;
int op = 0;
scanf("%d %c %d", &a, &ch, &b);
// ch = + :add, -:sub, *:mul, /:div
switch(ch)
{
case '+':
op = 0;
break;
case '-':
op = 1;
break;
case '*':
op = 2;
break;
case '/':
op = 3;
break;
}
void (*fp[4])(int *, int *, int *) = {add, sub, mul, div}; // 함수의 포인터
//int const *p = &a;
//int * const q = &a;
fp[op](&a, &b, &c);
fprintf(stdout, "%d %c %d = %d\n",a, ch, b, c);
fprintf(stdout, "a,b,c:%d %d %d\n", a, b, c);
fp[1](&a,&b,&c);
fprintf(stdout, "a,b,c:%d %d %d\n", a, b, c);
fp[2](&a,&b,&c);
fprintf(stdout, "a,b,c:%d %d %d\n", a, b, c);
fp[3](&a,&b,&c);
fprintf(stdout, "a,b,c:%d %d %d\n", a, b, c);
}
#include "func.h"
int func1(int a)
{
return (a*10);
}
int func2(int a)
{
return DF(a+1) *20;
}
#if FUNCTION_NEGATIVE == 1
#define DF(a) (-(a)*(a))
#else
#define DF(a) ((a)*(a))
#endif
extern int func1(int x);
extern int func2(int x);
File added
#include <stdio.h>
#define FUNCTION_NEGATIVE 1
#include "func.h"
int main()
{
printf("Func1 %d %d\n", func1(100), DF(10));
printf("Func2 %d %d\n", func2(100), DF(10));
}
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment