반응형

전체 글 738

[C언어 소스] 랜덤 값 맞추기

[C언어 소스] 랜덤 값 맞추기언제나 휴일 티스토리 //랜덤 값 맞추기#include #include #include int main(void){ int rand_num = 0; int count = 0; int guess = 0; srand((unsigned)time(0)); //프로그램을다시동작할 때 같은 값이 발생하지 않게 랜덤 시드 (Seed)값 설정 rand_num = rand() % 100; //랜덤 값 while (1) { printf("추측답: "); scanf_s("%d", &guess); if (guess == rand_num) { break; } if (guess

[C언어] 문자열에서 문자 제거

[C언어] 문자열에서 문자 제거언제나 휴일 티스토리 //문자열에서 문자 제거#include #include void Eliminate(char *str, char ch);int main(void){ char str[] = "Hello World"; Eliminate(str, 'l'); printf("%s\n", str); return 0;} void Eliminate(char *str, char ch){ for (; *str != '\0'; str++)//종료 문자를 만날 때까지 반복 { if (*str == ch)//ch와 같은 문자일 때 { strcpy(str, str + 1); str--; } } }

[C언어 소스] 이차 방정식 해 구하기

[C언어 소스] 이차 방정식 해 구하기언제나 휴일 티스토리 //2차 방정식의 근#include #include #pragma warning(disable:4996) int main(void){ double a, b, c, d, e; printf("이차방정식 ax^2+bx+c=0\n"); printf("a: "); scanf("%lf", &a); printf("b: "); scanf("%lf", &b); printf("c: "); scanf("%lf", &c); if (a == 0) { printf("x = %f \n", -c / b); } else { d = b*b - 4.0*a*c;//판별식 if (d>0) { e = sqrt(d); printf("두 개의 근: %f, %f \n", (-b + e) /..

[C언어 소스] 균형 원소 찾기

[C언어 소스] 균형 원소 찾기언제나 휴일 티스토리 //균형 원소 찾기 #include #include #include #define MAX 10000 void TestCase(int *base, int n);//TestCase int main(void) { int arr1[3] = { 1, 2, 3 }; int arr2[4] = { 1,2,3,3 }; TestCase(arr1, 3); TestCase(arr2, 4); return 0; } int FindBalance(int *base, int n);//균형 원소 찾는 함수 void TestCase(int *base, int n) { int i = 0; int balance; for (i = 0; i

[C언어 소스] 디지털 시계

[C언어 소스] 디지털 시계언제나 휴일 티스토리 #include #include #include #include #pragma warning(disable:4996)char*digits[10][5][4] =//0~9까지 출력할 정보{ { { "■","■","■","■" }, { "■"," "," ","■" }, { "■"," "," ","■" }, { "■"," "," ","■" }, { "■","■","■","■" } }, { { " "," "," ","■" }, { " "," "," ","■" }, { " "," "," ","■" }, { " "," "," ","■" }, { " "," "," ","■" } }, { { "■","■","■","■" }, { " "," "," ","■" }, { "■"..

[C언어 소스] 성적 관리 프로그램 - 이중 연결리스트

[C언어 소스] 성적 관리 프로그램 - 이중 연결리스트언제나 휴일 티스토리 //성적 관리 프로그램 - 이중 연결리스트//생성 순서로 연결 리스트에 보관//중복 데이터 처리 없음//입력 오류에 관한 예외 처리 없음 #include #include #include #include #define MAX_NLEN 20 //최대 이름 길이#define MAX_SUBJECT 3 //과목 수typedef struct Student {//학생 구조체 정의 char name[MAX_NLEN + 1];//이름 int num; //번호 int scores[MAX_SUBJECT];//국,영,수 성적 struct Student *next; struct Student *prev;}Student; const char *stitle..

[C언어 소스] 성적 관리 프로그램 - 학생 데이터 동적 메모리 할당

[C언어 소스] 성적 관리 프로그램 - 학생 데이터 동적 메모리 할당 //성적 관리 프로그램 - 배열을 동적 메모리 할당//학생 번호 순으로 동적 배열에 보관//학생 데이터도 동적으로 할당//최대 학생 수를 프로그림 시작 시에 사용자가 결정//입력 오류에 관한 예외 처리 없음 #include #include #include #include #define MAX_NLEN 20 //최대 이름 길이#define MAX_SUBJECT 3 //과목 수typedef struct {//학생 구조체 정의 char name[MAX_NLEN + 1];//이름 int num; //번호 int scores[MAX_SUBJECT];//국,영,수 성적}Student; const char *stitles[MAX_SUBJECT] =..

반응형