열렬히.뛰기

add_prime_sum

école 42 > exam02 > exam02 : part3 > add_prime_sum

공략법 && 주의점

  1. main() 작성
  2. x = ft_atoi(av[1])
    • av[1] == “0”이면 0을 보낸다.
    • av[1] == “-2147483648”
    • 이후 일반적인 ft_atoi()처럼 진행
    • 중간에 결과값이 0이면 -1 반환
  3. x부터 0까지 소수 파악해서 더한다.
    • 소수 파악 알고리즘 : i * i ≤ num 일 때까지 i를 돌리며 확인.
    • 나머지가 0이면 소수가 아님.
  4. 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$
$>