//1
#include <stdio.h>
int main() {
double x[3];
for (int i=0; i<3; i++)
printf("x[%d]์ ์ฃผ์ : %d\n", i, x+i);
return 0;
}
//2
#include <stdio.h>
int main() {
double x[10] = {0.1,2.0,3.4,5.2,4.5,7.8,9.7,1.4,6.6,7.2};
double* p = x; //๋ฐฐ์ด์ ์์์ฃผ์ ๊ฐ๋ฆฌํค๊ธฐ
for (int i=0; i<10; i++)
printf("%.1f ",*(p+i));
// p์ฆ ์์์ฃผ์ ์ฆ๊ฐ์ํค๊ณ ํ๋ํ๋ ์ฐธ์กฐํ์ฌ ์ถ๋ ฅ
return 0;
}
//3
#include <stdio.h>
int main() {
int arr[10] = { 44,32,65,23,45,76,77,89,23,45 };
int* p = arr;
printf("๋ฐฐ์ด :");
for (int i = 0; i < 10; i++, p++) {
printf("%d ", *p);
}
printf("\n");
p = &arr[9];
printf("์ญ์ :" );
for (int i = 0; i < 10; i++, p--) {
printf("%d ", *p);
}
return 0;
}
//4
#include <stdio.h>
int main() {
double x[10] = {0.1,2.0,3.4,5.2,4.5,7.8,9.7,1.4,6.6,7.2};
double sum=0, avg=0;
double* p = x; //๋ฐฐ์ด์ ์์์ฃผ์ ๊ฐ๋ฆฌํค๊ธฐ
printf("๋ฐฐ์ด: ");
for (int i=0; i<10; i++)
printf("%.2f ",*(p+i));
// p์ฆ ์์์ฃผ์ ์ฆ๊ฐ์ํค๊ณ ํ๋ํ๋ ์ฐธ์กฐํ์ฌ ์ถ๋ ฅ
printf("\n");
printf("ํ๊ท : ");
for (int i = 0; i < 10; i++)
sum += *(p + i);
avg = sum / 10.0;
printf("%f ", avg);
return 0;
}
//7
#include <stdio.h>
void reverse_array(double arr[10]);
int main() {
double arr[10] = { 4.4,3.2,6.5,2.3,4.5,7.6,7.7,8.9,2.3,4.5 };
double *p = arr;
printf("๋ฐฐ์ด :");
for (int i = 0; i < 10; i++, p++) {
printf("%.1f ", *p);
}
printf("\n");
printf("์ญ์ :" );
reverse_array(arr);
return 0;
}
void reverse_array(double arr[10]) {
double* p = arr;
p = &arr[9];
for (int i = 0; i < 10; i++, p--) {
printf("%.1f ", *p);
}
}
//9
#include <stdio.h>
void fill_2d_array(int *p, int size);
int main() {
int arr[4][5];
int* p = arr;
fill_2d_array(&arr, 4);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 5; j++) {
printf("%d",*p);
}
printf("\n");
}
return 0;
}
void fill_2d_array(int *p, int size) {
int n;
printf("๋ฐฐ์ด ์์์ ์ ์ฅํ ๊ฐ?");
scanf_s("%d", &n);
for (int i = 0; i < size; i++, p++) {
*p = n;
}
}
//11
#include <stdio.h>
void get_rect_info(int h, int w, int* a, int* c);
int main() {
int height, width;
int area = 0;
int circum = 0;
printf("๊ฐ๋ก?\n");
scanf_s("%d", &height);
printf("์ธ๋ก?\n");
scanf_s("%d", &width);
get_rect_info(height, width, &area, &circum);
printf("๋์ด : %d, ๋๋ : %d", area, circum);
return 0;
}
void get_rect_info(int h, int w, int *a, int *c) {
*a = h * w;
*c = (h + w) * 2;
}