본문 바로가기

프로그램/C언어 1000제227

C언어 131제] 게임 프로젝트 1. 두뇌 개발 프로젝트 Ver 0.1 출처 : 반크_세계유산 석굴암 문제] 임의의 자연수 두개를 발생하여 더하기 게임하기. 단계마다 5개의 문제를 맞추면 다음 단계로 진행할 수 있도록 한다. 단계가 끝나면 계속 작업여부를 체크한다. 작업을 끝내면 결과를 기준으로 능려자 여부를 출력한다. 프로그램] //Dev-C++ 5.11로 작업함. //두뇌 개발 프로그램 Ver 0.1 //더하기 게임 #include #include //srand(), rand() #include //time() int main() { int a,b;//문제 발생 변수 int player_answer;//문제에 대한 정답변수 int count;//맞춘 개수 변수 int total_count;//전체 문제를 세는 변수 int stage;//게임의 단계를 체크하는 변수 int.. 2022. 3. 15.
C언어 130제] C언어 콘서트 CHAPTER 14 Programming 4 p548 출처 : 반크_세계유산 석굴암 참고풀이] Visual Studio 2019에서 작업함. array.h) #ifdef ARRAY_H #define ARRAY_H int get_sum_of_array(int* M, int size); void Print_array(int* M, int size); #endif array.c) #include #include "array.h" int get_sum_of_array(int* M, int size) { int i; int h = 0; for (i = 0;i < size;i++) h += M[i]; return h; } void Print_array(int* M, int size) { int i; printf("[ "); for (i = 0;i < size;i++).. 2022. 2. 11.
C언어 129제] C언어 콘서트 CHAPTER 14 Programming 3 p547 출처 : 반크_세계유산 석굴암 참고풀이] Visual Studio 2019에서 작업함. hello.h) #ifdef HELLO_h #define HELLO_H void hello(char* name); #endif hello.c) #include #include "hello.h" void hello(char* name) { printf("안녕 %s\n", name); } main()가 있는 파일) #include #include "hello.h" int main() { hello("철수"); return 0; } 참고풀이 결과] 대한민국의 아름다운 영토, 독도의 여름 2022. 2. 11.
C언어 128제] C언어 콘서트 CHAPTER 14 Programming 2 p547 출처 : 반크_세계유산 석굴암 참고풀이] add.c 파일] #include int add(int x, int y) { return x+y; } c0130_p547_2.c : main()가 있는 파일] #include #include "add.c" int main() { printf("합계=%d\n",add(10,20)); return 0; } ※ add.c 와 main()가 있는 파일은 같은 디렉토리에 있도록 합니다. 참고풀이 결과] 대한민국의 아름다운 영토, 독도의 봄 2022. 2. 9.
C언어 127제] C언어 콘서트 CHAPTER 14 Programming 1 p547 출처 : 반크_세계유산 석굴암 참고풀이] #include #define DEBUG 1 #define SIZE 10 double calc_array_avg(int *P) { int Sum=0; int i; #ifdef DEBUG printf("calc_array_avg()\n"); for(i=0;i 2022. 2. 9.
C언어 126제] C언어 콘서트 CHAPTER 13 Programming 6 동적메모리를 활용하여 성적을 나타내는 구조체 프로그래 작성하기. p511 참고풀이] #include #include //malloc(), free(), exit() struct course{ char subject[30];//과목 이름 double marks;//학점 }; int main() { int N;//구조체의 개수 입력변수 struct course *M;//구조체의 개수에 해당하는 동적메모리 변수 int i;//반복변수 //구조체의 개수 입력 printf("구조체의 개수 : "); scanf("%d",&N); //동적메모리를 할당한다. M=(struct course *)malloc(sizeof(struct course *)*N); if(M==NULL) { printf("메모리 할당 오류\n"); exit(1); } //할당된 동적메모리에 과목과 학점을 넣는다. for.. 2022. 2. 8.
C언어 125제] C언어 콘서트 CHAPTER 13 Programming 5 구조체를 동적메모리 할당으로 생성하는 프로그램 작성하기. p511 출처 : 반크_세계유산 석굴암 참고풀이] #include #include //malloc(), free(), exit() typedef struct rec{ int i; float PI; char A; } my_record; int main() { //동적메모리를 할당한다. my_record *M=(my_record *)malloc(sizeof(my_record)*1); if(M==NULL) { printf("메모리 할당 오류\n"); exit(1); } //할당된 동적메모리에 값을 넣는다. M[0].i=10; M[0].PI=3.140000; M[0].A='a' ; //결과출력 printf("%d\n",M[0].i); printf("%f\n",M[0].PI); printf("%c\n",M[0].A); /.. 2022. 2. 8.
C언어 124제] C언어 콘서트 CHAPTER 13 Programming 4 정수 100개를 동적메모리 할당 후 저장하고 최대값을 구하기. p511 출처 : 반크_세계유산 석굴암 참고풀이] #include #include //malloc(), free(), srand(), rand() #include //time() int main() { int N;//입력될 자료의 개수변수 int i;//반복변수 int Max;//입력된 요소들의 최대값을 구할 변수 //동적메모리를 할당한다. int *M=(int *)malloc(sizeof(int)*100); //무작위 발생할 값을 초기화 한다. srand(time(NULL)); //할당된 동적메모리에 값을 입력한다. for(i=0;i 2022. 2. 8.
C언어 123제] C언어 콘서트 CHAPTER 13 Programming 3 정수 100개를 동적메모리에 임의의 저장 후 평균 구하기. p510 출처 : 반크_세계유산 고인돌 참고풀이] #include #include //malloc(), free(), srand(), rand() #include //time() int main() { int N;//입력될 자료의 개수변수 int i;//반복변수 int Sum;//입력된 요소들의 합을 구할 변수 //동적메모리를 할당한다. int *M=(int *)malloc(sizeof(int)*100); //무작위 발생할 값을 초기화 한다. srand(time(NULL)); //할당된 동적메모리에 값을 입력한다. for(i=0;i 2022. 2. 8.
C언어 122제] C언어 콘서트 CHAPTER 13 Programming 2 사용자가 입력한 n값의 실수들을 malloc()로 할당 저장하고 최대값을 구하기. p510 출처 : 반크_세계유산 고인돌 참고풀이] #include #include //malloc(), free() int main() { int N;//입력될 자료의 개수변수 int i;//반복변수 double Max;//입력된 요소들의 최대값을 구할 변수 printf("요소의 개수 : "); scanf("%d",&N); //동적메모리를 할당한다. double *M=(double *)malloc(sizeof(double)*N); //할당된 동적메모리에 값을 입력한다. for(i=0;i 2022. 2. 8.
C언어 121제] C언어 콘서트 CHAPTER 13 Programming 1 사용자가 입력한 n개의 실수의 합을 malloc()를 사용하여 구하기. p510 출처 : 반크_세계유산 고인돌 참고풀이] #include #include //malloc(), free() int main() { int N;//입력될 자료의 개수변수 int i;//반복변수 double Sum;//입력된 요소들의 합을 구할 변수 printf("요소의 개수 : "); scanf("%d",&N); //동적메모리를 할당한다. double *M=(double *)malloc(sizeof(double)*N); //할당된 동적메모리에 값을 입력하고 합을 구한다. Sum=0.; for(i=0;i 2022. 2. 8.
C언어 120제] C언어 콘서트 CHAPTER 12 Programming 12 소규모의 데이터베이스 프로그램 작성. p491 출처 : 반크_세계유산 고인돌 참고풀이] //Dev-C++ 5.11로 작업함. #include #include //exit(), toupper() #include //strlen(), strstr(), strcmp(), strcpy(), strcat() FILE *fp1; struct Book{ char bookname[50]; char author[20]; char publisher[30]; }Books; char StrLine[255]; int chk; void Menu(); void Append(); void Print(); void Print_title(); void Print_List(char *Str); void Find(char *F); int main(void) { char Chk[255].. 2022. 2. 8.
반응형