Small Grey Outline Pointer 'Dev.' 카테고리의 글 목록 (17 Page)
본문 바로가기

Dev.218

CodeUp c++ 1420 : 3등 찾기 #include #include //3등찾기 int main() { int n; int score[51]; //점수 저장 int rank[51]; // 순위 저장 char name[50][50]; //이름 [순서][이름] scanf("%d", &n); for (int i = 1; i 2022. 4. 9.
CodeUp c++ 1416 : 2진수 변환 #include //10진수를 2진수로 바꾸기 int main() { int n; int cnt = 0; //자릿수 int arr[10000]; scanf("%d", &n); while (1) { arr[cnt] = n % 2; n = n / 2; cnt++; //2로 나눠질 때 마다 카운트 업 if (n == 0) { break; } } for (int i = cnt -1 ; i >= 0; i--) { //배열에 저장된 순서를 역으로 출력 printf("%d", arr[i]); } } 7 111 배열을 이용하여 while문으로 반복 2진수는 10진수를 2로 나눈 몫...나머지로 표기됨 따라서 2로 나눈 몫을 카운트 한다 2022. 4. 9.
구조체 종합문제 배열 SWAP 하기 #include #include #include typedef struct { int xpos; int ypos; }Point; void printPoint(Point point) { printf("x: %d, y:%d\n", point.xpos, point.ypos); } void prac2002() { Point position1 = { 3,6 }; Point position2 = { 4,9 }; Point temp; temp = position1; position1 = position2; position2 = temp; printPoint(position1); printPoint(position2); } void main() { prac2002(); } x: 4, y:9 x: 3.. 2022. 4. 6.
구조체배열 응용문제 #include #include #include struct person { char name[30]; int number; int age; }; void ex1903() { struct person boy[3]; struct person girl[3]; for (int i = 0; i < 3; i++) { printf("소년 이름을 입력하세요: "); //scanf("%s", boy[i].name); scanf("%s", boy[i].name); printf("소년 나이를 입력하세요: "); scanf_s("%d", &boy[i].age); //printf("소년 번호를 입력하세요: "); //scanf_s("%d", &boy[i].number); } for (int i = 0; i < 3; i++) .. 2022. 4. 5.
구조체와 배열/구조체와 포인터 구조체별명, 초기화 #include typedef struct Fruit { char name[200]; int price; char season[200]; }F; //구조체별명 void main() { F apple = { "사과", 1500, "가을" }; F pear = { "배", 3500, "겨울" }; F banana = { "바나나", 500, "여름" }; printf("%s %d %s\n", apple.name, apple.price, apple.season); printf("%s %d %s\n", pear.name, pear.price, pear.season); printf("%s %d %s\n", banana.name, banana.price, banana.season); } 사과 1.. 2022. 4. 5.
메모리의 동적할당/malloc 메모리의 동적 할당 #include #include #include void ex1802() { int arrsize, darrsize; printf("arr size, darrsize 입력: "); scanf_s("%d %d", &arrsize, &darrsize); int* iptr = (int*)malloc(sizeof(int) * arrsize); double* dptr = (double*)malloc (sizeof(double) * darrsize); int i; printf("int 값 출력 및 입력 \n"); for (i = 0; i < arrsize; i++) { printf("%d번째 array값 입력: "); scanf_s("%d", &iptr[i]); } for (i = 0; i < .. 2022. 4. 4.
구조체 [구조체] 공통 요소(멤버 변수)로 구조화(구체화) 시켜 놓은 것 후에 이러한 구조체의 개념은 객체 지향 프로그래밍에서는 class 개념으로 확장되어 사용된다 배열:여러개의 같은 자료형을 하나로 묶는 것 구조체:서로 다른 자료형들을 하나로 묶는 것 [목적] 반복되는 공통 요소를 쉽게 관리 하기 위해서 [구조체 선언] struct 구조체 이름 { 자료형 멤버변수명, }; typedef struct 구조체이름 { 자료형 멤버변수명, }구조체별명; [선언시 주의사항] -함수 밖에서 선언해야 한다 -선언 시 멤버 변수에 초기값을 넣을 수 없다 [구조체 사용] struct 구조체이름 변수명; 구조체이름.멤버변수명=값; struct 구조체이름 변수명={값,....}; typedef 을 선언했다면 아래와 같이 사용한.. 2022. 4. 4.
CodeUp c++ 1411 : 빠진 카드 첫 줄에는 한 장을 잃어버리기 전 카드의 전체 장수 N이 주어져 있다. 단 . 3 2022. 4. 3.
CodeUp c++ 1410 : 올바른 괄호 1 (괄호 개수 세기) 소괄호로 이루어진 문자열을 주어지면 괄호의 개수를 출력하는 프로그램을 작성하시오. #include #include int main() { // ( 40 // ) 41 char a[100001]; int cnt = 0; int cnt2=0; int end; gets(a); //printf("%s", input); end = strlen(a); for (int i = 0; i < end; i++) { if (a[i]==40) { cnt++; } else if (a[i] == 41) { cnt2++; } } printf("%d %d", cnt, cnt2); } ((() 3 1 ()()()(((((( 9 3 처음에 배열을 a[100000] 으로 설정해서 오류 발생 buffer overflow detected:버.. 2022. 4. 3.
CodeUp c++ [1차원배열] 1407 : 문자열 출력하기/공백 지우는 함수 만들기 길이(글자수)가 100이하인 문자열을 입력받아 공백을 제거하고 출력하시오. #include #include //1차원 배열-문자열 출력하기 //문자열에서 공백 지우는 함수 만들기 void EraseSpace(char word[]) { char temp[100]; int k = 0; for (int i = 0; i 2022. 4. 3.