본문 바로가기

전체 글

(52)
배열 문제 개요 배열 days[] 를 아래와 같이 초기화하고 배열 원소의 값을 다음과 같이 출력하는 프로그램 을 작성하라. 목표 1월은 31일까지 있습니다. 2월은 29일까지 있습니다. ..... Code #include int main(void) { int days[] = { 30,29,31,30,31,30,31,31,30,31,30,31 }; for (int i = 1; i aRand[j]) { temp = aRand[i]; aRand[i] = aRand[j]; aRand[j] = temp; } } } for (int i = 0; i < 10; i++) { printf("%5d", aRand[i]); } printf("\nMIN : %d\tMAX : %d",aRand[0],aRand[9]); } Output 개..
구조체 문제 개요 구조체를 이용하여 복소수를 다음과 같이 정의하고 복소수의 덧셈을 수행하는 함수를 작성하고 테스트하시오.​ Code #include typedef struct complex{ double real; double imag; }Com_s; Com_s com_add(Com_s c1, Com_s c2); int main(void) { Com_s c1, c2, res; printf("Input 1st complex No. : "); scanf_s("%lf %lf",&c1.real,&c1.imag); printf("Input 2nd complex No. : "); scanf_s("%lf %lf", &c2.real, &c2.imag); res = com_add(c1,c2); printf("Result : %0.2..
최대 최소 구하기(bubble sort) 개요 5개의 숫자를 입력 받고 최대값과 최소값을 구하라. Code #include #define MAX 5 void input(int arr[]); void maxmin(int arr[]); void output(int arr[]); int main(void) { int arrInt[MAX]; input(arrInt); maxmin(arrInt); output(arrInt); return 0; } void input(int arr[]) { for (int i = 0; i < MAX; i++) { printf("%d번째 숫자 :",i+1); scanf_s("%d", &arr[i]); } } void maxmin(int arr[]) { int i, j, temp; for (i = 0; i < MAX ; i+..
String 관련 예제 개요 1. 문자열 안에 포함된 특정한 문자의 개수를 세는 함수 int str_chr(char *s, int c)를작성하라. s는 문자열이고 c는 개수를 셀 문자이다. 목표 실행결과 문자열을 입력하시오: I am a boy 개수를 셀 문자를 입력하시오: a a의 개수: 2 Code #include #include #define INSIZE (unsigned)sizeof int str_chr(char* s, int c); int str_chr(char* s, int c) { int cnt = 0; for (int i = 0; i
구조체 실습과제 01 개요 성적처리 할 학생의 수를 사용자로부터 입력받고, 사용자가 입력한 수만큼의 학생에 대해 이름과 국어,영어,수학 성적을 입력받아 총점과 평균을 계산하여 출력하는 프로그램을 작성하세요. Code #include #include #include #define MAX_NAME 20 #define SUBJECTS 3 typedef struct Grade { char name[MAX_NAME]; int score[SUBJECTS]; int total; double average; }gr_t; typedef enum SubjectName { kor, eng, math }Sub_e; typedef enum ModeSelect { data_in, data_out }MS_e; void InputGrade(gr_t* i..
Structure Input/Output 개요 구조체를 이용하여 입력을 받고 출력하라. 목표 입력화면 가족(아빠)의 성을 입력하세요 = 박 가족(엄마)의 성을 입력하세요 = 김 1 번째 가족 신상을 입력합니다. 가족관계를 선택하세요. 부(0), 모(1), 형제(2), 자매(3) = 0 이름을 입력하세요 = 장군 나이를 입력하세요 = 50 전화 번호를 입력하세요 = 010-1111-2222 2 번째 가족 신상을 입력합니다. 가족관계를 선택하세요. 부(0), 모(1), 형제(2), 자매(3) = 1 이름을 입력하세요 = 사랑 나이를 입력하세요 = 40 전화 번호를 입력하세요 = 010-2222-3333 3 번째 가족 신상을 입력합니다. 가족관계를 선택하세요. 부(0), 모(1), 형제(2), 자매(3) = 2 이름을 입력하세요 = 왕자 나이를 입력..
소수 구하기 2 개요 입력받은 수까지 모든 소수를 구하고 출력하라. 에라토스테네스의 체의 방법 - 2의 배수를 소수에서 제외, 3의 배수를 소수에서 제외.... 즉 소수의 배수를 소수에서 제외해서 소수를 구하는 방법 Code #include #include void FindPrimeNumber(int* pArray, int index,int L_num) { int i = index; while (i+index
소수 구하기 개요 입력받은 수까지 모든 소수를 구하고 출력하라. Code #include #include #include int main(void) { int* ptrPrime=NULL; int iNum,snCnt; printf("소수를 찾을 최대수를 입력하세요 : "); scanf_s("%d", &iNum);//숫자 입력 //입력받은 숫자크기의 포인터 선언 ptrPrime = (int*)malloc(sizeof(int*)*iNum); //arrary에 0~입력받은 숫자까지 입력 for (int i = 0; i 2) { ptrPrime[i] = 0; } } //구한 소수를 출력 for (int i = 2, cnt = 0; i