공략법
while 문을 무한히 돌리면서…
- 약수일 경우 :
- i 출력
- num/i 하기
-
- 출력
- 약수가 아닐 경우 : i값 증가
이후 2번과 3번 사이에 num == 1인 경우를 생각해준다.
더 이상 출력이 되면 안되므로, 여기에서 return을 넣어준다.
- 0보다 작은 수 = 0과 음수 ⇒ 출력 안함
- 1은 무조건 1로.
문제
c
Assignment name : fprime
Expected files : fprime.c
Allowed functions: printf, atoi
--------------------------------------------------------------------------------
Write a program that takes a positive int and displays its prime factors on the
standard output, followed by a newline.
Factors must be displayed in ascending order and separated by '*', so that
the expression in the output gives the right result.
If the number of parameters is not 1, simply display a newline.
The input, when there is one, will be valid.
Examples:
$> ./fprime 225225 | cat -e
3*3*5*5*7*11*13$
$> ./fprime 8333325 | cat -e
3*3*5*5*7*11*13*37$
$> ./fprime 9539 | cat -e
9539$
$> ./fprime 804577 | cat -e
804577$
$> ./fprime 42 | cat -e
2*3*7$
$> ./fprime 1 | cat -e
1$
$> ./fprime | cat -e
$
$> ./fprime 42 21 | cat -e
$