main.m435 chars16 lines
The code above prompts the user for a positive integer n, initializes a variable sum_nonpos_primes as 0, loops through the numbers from -2 to -n, and checks if each number is a non-positive prime using the isprime function and a conditional statement. If a number is a non-positive prime, it adds it to the sum sum_nonpos_primes. Finally, it displays the result of sum_nonpos_primes. Note that we use the abs function to make sure that we only check the absolute value of each number for primality.
gistlibby LogSnag