Develop
2003.04.23 10:46
[c] 약수/최대공약수/완전수 알고리즘
Views 8863 Comment 0
# 약수 구하는 알고리즘..
#include<stdio.h> void main() { int i, j, n, m; scanf("%d", &n); for(i=1 ; i j = n / i; m = j * i; if( !(n-m) ) printf("%d ", i); } }
# 최대 공약수 구하는 알고리즘 (유클릿 알고리즘)
#include<stdio.h> int gcd(int m, int n) { if (m<=0) return 0; if (n<=0) return 0; while(m != n){ if (m>n) m = m - n; else n = n - m; } return n; } void main() { int a,b; printf("Enter a first Number : "); scanf("%d",&a); printf("Enter a second Number : "); scanf("%d",&b); printf("GCD is %d",gcd(a,b)); getch(); }
# 완전수 구하는 알고리즘
완전수란 자신을 제외한 약수의 합과 같은 양의 정수를 말한다.
#include<stdio.h> void main() { int i, j, n, m, sum; for(n=0; n<500; n++) { sum=0; for(i=1 ; i j = n / i; m = j * i; if( !(n-m) ){ //printf("%d ", i); sum+=i; } } if(n==sum) printf("n%d is Perfact!n", n); //else printf("n%d is Not! (%d!=%d)n", n, sum, n); } }
-
[c] 이진트리(binary tree)의 운행..
-
[c] 이진트리(binary tree) 샘플소스 (삽입, 삭제, 운행)
-
[c] 이진 탐색 두 가지 코드 (재귀/반복)
-
[c] 유닉스 프로그램에서 인수처리 해주는 getopt() 함수
-
[c] 윈도우 API Viewport와 Window
-
[c] 윈도우 API sin 함수 출력..
-
[c] 웹 메모장.. ㅋㅋ
-
[c] 웅지학원 NAT를 소스코드로..
-
[c] 오목.. 간단한 소스 ㅋㅋ
-
[c] 오류체크(CRC 체크 ) 소스
-
[c] 연산자 우선순위.. ㅋㅋ
-
[c] 약수/최대공약수/완전수 알고리즘