1. dArTask.c
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
void sortASC(int arData[], int length);
void sortDESC(int arData[], int length);
void main() {
//정수 개수 입력받고 그 만큼 할당하기
//입력받은 정수로 오름차순(void 함수) 또는 내림차순(void 함수) 선택 후 결과 출력
//1.오름차순\n2.내림차순\n3.나가기
int* dArNum = 0;
int length = 0;
int choice = 0;
char* dot[] = { ".", "..", "..." };
char* loading[] = { "■□□□□□□□□", "■■□□□□□□□", "■■■□□□□□□", "■■■■□□□□□", "■■■■■□□□□", "■■■■■■□□□", "■■■■■■■□□", "■■■■■■■■□", "■■■■■■■■■" };
while (1) {
printf("[정렬 프로그램]\n");
printf("①오름차순\n②내림차순\n③나가기\n");
scanf_s("%d", &choice);
if (choice == 3) { break; }
if (choice == 1 || choice == 2) {
printf("입력하실 정수개수 : ");
scanf_s("%d", &length);
dArNum = (int*)malloc(sizeof(int) * length);
for (int i = 0; i < length; i++) {
printf("%d번째 정수 : ", i + 1);
scanf_s("%d", dArNum + i);
}
//0 1 2 3 4 5 6 7 8 : 000 111 222
for (int i = 0; i < 9; i++) {
system("cls");
printf("%s\n", loading[i]);
printf(" 정렬중%s\n", dot[i / 3]);
Sleep(300);
}
switch (choice) {
case 1:
sortASC(dArNum, length);
break;
case 2:
sortDESC(dArNum, length);
break;
}
//결과 :
//각 정수는 0.5초에 하나씩 출력된다.
printf("결과 : ");
for (int i = 0; i < length; i++) {
Sleep(500);
printf("%d ", dArNum[i]);
}
printf("\n");
}
}
free(dArNum);
}
void sortASC(int arData[], int length) {
int temp = 0;
for (int i = 0; i < length - 1; i++) {
for (int j = i + 1; j < length; j++) {
if (arData[i] > arData[j]) {
temp = arData[i];
arData[i] = arData[j];
arData[j] = temp;
}
}
}
}
void sortDESC(int arData[], int length) {
int temp = 0;
for (int i = 0; i < length - 1; i++) {
for (int j = i + 1; j < length; j++) {
if (arData[i] < arData[j]) {
temp = arData[i];
arData[i] = arData[j];
arData[j] = temp;
}
}
}
}
2. star_graph.c
** 내가 만든 코드 **
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
void main() {
//학생 수를 입력받고 그만큼 동적할당
//학생별 점수 입력
//ㅂ한자를 누르면 x축과 y축을 이어서 그릴 수 있다.
//│★
//│★★
//└────
//학생 수
int num = 0;
printf("학생 수를 입력하세요 : ");
scanf_s("%d", &num);
//점수를 저장하기 위한 동적할당
int* score = (int*)malloc(sizeof(int) * num);
//학생수만큼 점수 입력 받기
for (int i = 0; i < num; i++) {
printf("학생별로 점수를 입력하세요(십단위로 입력 요망) : ");
scanf_s("%d", score + i);
}
system("cls");
printf("[학생별 점수 그래프]\n\n");
//점수 그래프
for (int i = 100; i > 0; i -= 10) {
printf("%3d│", i);
for (int j = 0; j < num; j++) {
if (i <= score[j]) {
printf(" ★");
} else {
printf(" ");
}
}
printf("\n");
}
printf(" └───────────────────\n ");
for (int i = 0; i < num; i++) {
printf("%5d", score[i]);
}
printf("\n\n\n");
}
** 쌤이 만든 코드 **
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
void main() {
//학생 수를 입력받고 그 만큼 동적할당
//학생별 점수 입력
//ㅂ한자를 누르면 x축과 y축을 이어서 그릴 수 있다.
//│★
//│★ ★
//└──────
int* arScore = 0;
int cnt = 0;
printf("학생 수 : ");
scanf_s("%d", &cnt);
arScore = (int*)malloc(sizeof(int) * cnt);
for (int i = 0; i < cnt; i++) {
printf("%d번째 학생 점수 : ", i + 1);
scanf_s("%d", arScore + i);
}
for (int i = 10; i > 0; i--) {
printf("%3d │", i * 10);
for (int j = 0; j < cnt; j++) {
if (arScore[j] >= i * 10) {
//별
printf(" ★ ");
}
else {
//공백
printf(" ");
}
}
printf("\n");
}
printf("%3d └─", 0);
for (int i = 0; i < cnt; i++) {
printf("──────");
}
printf("\n ");
for (int i = 0; i < cnt; i++) {
printf(" %d ", arScore[i]);
}
printf("\n");
}
3. graph.c
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
void main() {
//학생 수를 입력받고 그 만큼 동적할당
//학생별 점수 입력
//ㅂ한자를 누르면 x축과 y축을 이어서 그릴 수 있다.
//│★
//│★ ★
//└──────
int* arScore = 0;
int cnt = 0;
printf("학생 수 : ");
scanf_s("%d", &cnt);
arScore = (int*)malloc(sizeof(int) * cnt);
for (int i = 0; i < cnt; i++) {
printf("%d번째 학생 점수 : ", i + 1);
scanf_s("%d", arScore + i);
}
system("cls");
for (int i = 10; i > 0; i--) {
printf("%3d │", i * 10);
for (int j = 0; j < cnt; j++) {
if (arScore[j] >= i * 10) {
if (arScore[j] == i * 10) {
//뚜껑
printf(" ┌─┐ ");
}
else {
//막대
printf(" │ │ ");
}
}
else {
//공백
printf(" ");
}
Sleep(200);
}
printf("\n");
}
printf("%3d └─", 0);
for (int i = 0; i < cnt; i++) {
printf("┴─┴──");
Sleep(200);
}
printf("\n ");
for (int i = 0; i < cnt; i++) {
printf(" %d ", arScore[i]);
Sleep(200);
}
printf("\n");
}
4. dArrTest.c
#include<stdio.h>
#include<stdlib.h>
void main() {
int** dArr = (int**)malloc(sizeof(int*) * 2);
for (int i = 0; i < 2; i++) {
dArr[i] = (int*)malloc(sizeof(int) * 3);
}
for (int i = 0; i < 2; i++) {
free(dArr[i]);
}
free(dArr);
}
'웹_프론트_백엔드 > 단과' 카테고리의 다른 글
[단과_C] 2020.03.24 (0) | 2020.03.25 |
---|---|
[단과_C] 2020.03.23 (0) | 2020.03.23 |
[단과_C] 2020.03.19 (0) | 2020.03.20 |
[단과_C] 2020.03.18 (0) | 2020.03.18 |
[단과_C] 2020.03.17 (0) | 2020.03.18 |