Practice implementing functions Objectives Related knowledge A prime is positive integer that is greater than 1 and it i
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Practice implementing functions Objectives Related knowledge A prime is positive integer that is greater than 1 and it i
Practice implementing functions Objectives Related knowledge A prime is positive integer that is greater than 1 and it is the multiple of 1 and itself only. Theorem: The integer n is a prime if and only if n>1 and it can not be divided by all integers from 2 to square root of n. Use the library math.h to get the function sqrt(double) for getting the square root of a positive number. Problem Write a C program that will: - permit user inputting a positive integer n, n>=2 print out primes between 2 and n Analysis Suggested algorithm (logical order of verbs) Nouns: positive integer Begin → int n Do { Accept n; } While (n<2); For (i=2 to n ) End If (i is a prime ) Print out i; // Function check prime