MapleStory Finger Point

๐Ÿ”ต C,C++,C#/๐Ÿ“šCore C_Programming

[C/Core C Programming] Chapter8

HYEJU01 2023. 3. 27. 19:20
//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;

}