반응형
- _21_문제
- 문제027_포인터와함수05.cpp
#include <stdio.h>
#include <stdlib.h>
double h(double *f, int d, double x){
int i;
double res = 0.0;
for(i = d-1; i >= 0; i--){ // 3 ; i >=0
//3 2 1 0
res = res * x + f[i];
// 0 * 2 + 4 // 4
// 4 * 2 + 3 // 11
// 11 * 2 + 2 // 24
// 24 * 2 + 1 // 49
printf("%3.1f \n" , res); //50
}
return res;
}
int main(void) {
double f[] = {1, 2, 3, 4};
double res = h(f, 4, 2);
printf("%3.1f \n" , res);
return 0;
}
// 102번
- 문제027_포인터와함수06.cpp
#include <stdio.h>
#include <stdlib.h>
void func(int *a, int b, int *c);
int main(void) {
int a, b, c[1];
a = 20;
b = 20;
c[0] = 20;
func(&a, b, c);// &c[0]
printf("%d %d %d\n" , a , b , c[0]); // 20 20 19
return 0;
}
//x1 , 20 , x5
void func(int *a, int b, int *c){
int x;
x = *a; //x = 20
*a = x ++; //a = 20 , x = 21
x = b; //x = 20
b = ++x; //b = 21 ,x = 21
--(*c);//19
}
// 102번
- 문제027_포인터와함수07.cpp
#include <stdio.h>
#define SIZE 3
void func(int *m, int *a, int b);
int main(void) {
int num[SIZE] = {1, 3, 6};
int a = 10, b = 30;
func(num, &a, b);
printf("%d %d \n",a , b); // 7 30
return 0;
}
//x1, x 13 , 30
void func(int *m, int *x, int y){
int i = 0, n = 0;
y = *x; //y = 10
//n = 3 + 3 // n = 6
n = *(m + 1) + (*m + 2);
//a = 7
*x = ++n;
}
- 문제027_포인터와함수08.cpp
#include <stdio.h>
#define SIZE 3
//10 , x1
int* func(int a, int *x){
a = a + 10; // a = 20
x = x + 1; // x5
*x = *x * 2;//*(x5) =>a[1] => 20
return x;
}
int main(void) {
int i;
int x = 10;
int *p;
int a[100];
for (i = 0; i < 100; i++)
a[i] = i * 10; // 0, 10, 20, ... 990
p = func(x, a); //x5
int sum = x + a[0] + a[1] + p[0] + p[1];
//10 + 0 + 20 + 20 +20 =70
//p[0] == a[1] , // p[1] == a[2]
printf("%d\n" , sum);
return 0;
}
- 문제027_포인터와함수09.cpp
#include <stdio.h>
void funCount();
int main(void) {
int num;
//2번 동작 //0,1 => funCount()가 두번 동작
for(num = 0; num < 2; num++)
funCount();
return 0;
}
void funCount(){
int num = 0;
static int count;
printf("%d %d\n" , ++num, count++); //1, 0 // 1 1
}
- 문제027_포인터와함수11.cpp
#include <stdio.h>
int funcA(int n){
static int s = 1;
s *= n;
return s;
}
int funcB(int n){
int s = 1;
s *= n;
return s;
}
int main(void) {
int s1, s2;
s1 = funcA(2);
printf("%d\n" , s1); //2
s1 = funcA(3);
printf("%d\n" , s1); //6
s2 = funcB(2);
printf("%d\n" , s2); //2
s2 = funcB(3);
printf("%d\n" , s2); //3
return 0;
}
- 문제027_포인터와함수12.cpp
#include <stdio.h>
void func();
int a = 10;
int b = 20;
int c = 30;
int main(void) {
func();
func();
printf("%d %d %d\n" , a , b , c); //10 20 102
return 0;
}
void func(){
static int a = 100;
int b = 200;
a ++;
b ++;
c = a;
}
반응형
'코딩 > C언어' 카테고리의 다른 글
_21_문제 => 문제028_재귀함수 ~ 문제028_재귀함수11_01 (0) | 2025.07.17 |
---|---|
_21_교재 => 수업027_포인터와함수 , _21_문제 => 문제027_포인터와함수~문제027_포인터와함수04 (0) | 2025.07.15 |
수업026_구조체 (0) | 2025.07.11 |
문제024_포인터와이차배열 ~ 문제024_포인터와이차배열07 (0) | 2025.07.10 |
수업024_포인터와이차배열 (11) | 2025.07.09 |