전체 글
IT, 일상, 독서록, 일기 등 자유로운 주제의 포스팅을 합니다.it/programming
[ C++ ] Call by reference 기법을 이용한 최대값 구하기
#include void max(int* a, int* b, int* c) { if(*a
it/programming
[ C++ ] ctype.h 함수를 이용한 문자 치환
#include #include void main() { char c; printf("문자 입력 : "); scanf("%c", &c); if(isupper(c)) printf("%c\n",tolower(c)); else if(islower(c)) printf("%c\n",toupper(c)); }
it/programming
[ C++ ] Call by reference 기법을 이용한 swap 함수
#include void swap(int* a, int* b) { int temp; temp = *b; *b = *a; *a = temp; } void main() { int a, b; printf("두 수 입력 : "); scanf("%d %d", &a, &b); printf("a : %d, b : %d\n",a,b); swap(&a,&b); printf("a : %d, b : %d\n",a,b); }
it/programming
[ C++ ] 사용자 정의 함수를 이용한 최대 공약수 구하기
#include int cg(int a, int b) { int temp; while(a-b!=0) { if(b>a) { temp = a; a = b; b = temp; } temp = a-b; a = b; b = temp; } return b; } void main() { int a,b; printf("두수 입력 : "); scanf("%d %d", &a, &b); printf("최대 공약수 : %d\n",cg(a,b)); }
반응형