[工學(공학) ] 자료구조 - 순환과 반복
페이지 정보
작성일 22-12-14 05:51
본문
Download : [공학] 자료구조 - 순환과 반복.hwp
[공학] 자료구조 - 순환과 반복 , [공학] 자료구조 - 순환과 반복공학기술레포트 , [공학] 자료구조 - 순환과 반복
설명
reference(자료)구조 - 순환과 반복
1. 팩토리얼계산
◎순환
#include `iostream`
using namespace std;
int factorial(int n)
{
if(n1)
return 1;
else
return (n factorial(n-1));
}
void main()
{
int n;
cout `` `정수 입력 : `;
cin `` n;
cout `` n `` ` 팩토리얼 계산 : ` `` factorial(n) `` endl;
}
◎반복
#include `iostream`
using namespace std;
int factorial_iter(int n)
{
int k, v〓1;
for(k〓n; k`0; k)
v 〓 v k;
return v;
}
void main()
{
int n;
cout `` `정수 입력 : `;
cin `` n;
cout `` n `` ` 팩토리얼 계산 : ` `` factorial_iter(n) `` endl;
}
2. 예제프로그램(program]) 함수p()
◎ 순환
#include `iostream`
using namespace std;
void p(int n)
{
if(n`0)
{
p(n-2);
cout `` n;
p(n-1);
}
}
int main()
{
p(4);
return 0;
}
3.최대 공약수
◎ Recursive version
#include `iostream`
using namespace std;
int gcd(int x,int y)
{
return y gcd(y,x%y) : x ;
}
void main()
{
int x,y;
cout `` `정수 2개 입력 : ` ;
cin `` x `` y;
cout `` x `` `와 ` `` y `` `의 최대공약수 : ` `` gcd(x,y) `` …(drop)
[공학],자료구조,-,순환과,반복,공학기술,레포트
순서
[工學(공학) ] 자료구조 - 순환과 반복
Download : [공학] 자료구조 - 순환과 반복.hwp( 37 )
[工學(공학) ] 자료구조 - 순환과 반복
레포트/공학기술
다.


