C 프로그래밍(29)
-
문자열 버블정렬~
#include #include #include #define SIZE 1024 void bubbleSort(char *str); void swap(char *base, char *target); int getSize(char *str); void bubbleSort(char *str){ int i, j; for(i = 0 ; i < getSize(str) ; i++) { for (j = 0 ; j < getSize(str) ; j++) { if (str[i] < str[j]) swap(&str[i],&str[j]); } } } int getSize(char *str){ int size = 0; int i; for(i = 0;;i++){ if(str[i] == '\0') break; else size++..
2008.04.11 -
단어의 갯수 골라내기 확장팩
#include #include #include #define SIZE 1024 int word_cnt(); int word_cnt(char *string){ int count = 0; int nonAlphaContinued = 0; while(*string != '\0'){ // 문장이끝날대 while (isspace(*string)) // 포인터가가르키는인덱스가공백인경우 string++; //다음인덱스로포인터를변경 if(*string != '\0'){ count++; while (!isspace(*string) && *string != '\0') { // 빈칸이아니고, 문장이끝이나지도않을때 if (isalpha(*string)) {// 알파벳인경우 string++; } else if(isalpha(*..
2008.04.11 -
단어의 갯수를 세는 소스
#include #include #include #define SIZE 1024 int word_cnt(); int word_cnt(char *string){ int count = 0; while(*string != '\0'){ // 문장이 끝날대 while (isspace(*string)) // 포인터가 가르키는 인덱스가 공백인 경우 string++; //다음 인덱스로 포인터를 변경 if(*string != '\0'){ count++; while (!isspace(*string) && *string != '\0') string++; } } return count; } int main(){ char string[SIZE]; printf("입력하신 단어의 수를 세는 프로그램이다?"); gets(string..
2008.04.08 -
calloc 함수를 통한 동적 2차원 배열 만들기
#include #include int main(){ int iNum, i, j, temp; int **value; int first = 0; int last = 300; printf("몇 명인가요?\n"); scanf("%d", &iNum); value = (int **)calloc(iNum, sizeof(int *)); for(i = 0 ; i < iNum ; i++) { value[i] = (int *)calloc(4, sizeof(int)); printf("성적을 입력해주세요\n"); for (j = 0 ; j < 3 ; j++) { printf("점수?\n"); scanf("%d", &temp); value[i][j] = temp; value[i][3] += temp; } } for(i = 0 ..
2008.04.04 -
에라토스테네스의 체(Stieve of Eratosthenes) 에 근거한 소수 구하기
#include #define SIZE 100 void crossOut(int *s, int interval, int start){ int i; for (i = start; i < SIZE; i += interval){ s[i] = 0; } } void main(){ int prime[SIZE] = { 0 }; int i, j; printf("Table of primes to 100\n"); prime[0] = 0; for (i = 2; i < SIZE; i++) prime[i] = 1; for (i = 2; i < SIZE; i++){ crossOut(prime, i, i+i); } for (j = 3; j < SIZE; j++){ crossOut(prime, i, i+i); } for (i = 0; ..
2008.04.01 -
연습문제 13번 : 난수발생, 정수 갯수 세기
#include #include void display(int occurList[], int size); void validateNum(int numList[], int occurList[], int occurListSize); void display(int occurList[], int size){ int i = 0; for (i = 0 ; i < size ; i ++) if (occurList[i] != 0) printf("%d 는%d 번있었습니다.\n", i+1, occurList[i]); } void validateNum(int numList[], int occurList[], int occurListSize){ int i, temp; for (i = 0 ; i < 7 ; i ++){ temp =..
2008.03.28