공략법 && 주의점
- main() 작성
x = ft_atoi(av[1])av[1] == “0”이면 0을 보낸다.av[1] == “-2147483648”면- 이후 일반적인
ft_atoi()처럼 진행 - 중간에 결과값이 0이면 -1 반환
- x부터 0까지 소수 파악해서 더한다.
- 소수 파악 알고리즘 :
i * i ≤ num일 때까지 i를 돌리며 확인. - 나머지가 0이면 소수가 아님.
- 소수 파악 알고리즘 :
ft_putnbr()로 sum을 출력- x ≥ 10 인지 확인.
문제
c
Assignment name : add_prime_sum
Expected files : add_prime_sum.c
Allowed functions: write, exit
--------------------------------------------------------------------------------
Write a program that takes a positive integer as argument and displays the sum
of all prime numbers inferior or equal to it followed by a newline.
If the number of arguments is not 1, or the argument is not a positive number,
just display 0 followed by a newline.
Yes, the examples are right.
Examples:
$>./add_prime_sum 5
10
$>./add_prime_sum 7 | cat -e
17$
$>./add_prime_sum | cat -e
0$
$>