P5.5 isPrime Function. A prime number is a number that is only evenly divisible
ID: 3765574 • Letter: P
Question
P5.5 isPrime Function. A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6. Write a function name isPrime, which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise. Write a main function that makes use of the isPrime function to display all prime numbers from 1 through 100. Note: display five prime numbers per line as shown in the sample display.
C: Windows system32cmd.exe iplayed below are primie numbers less than 150: 13 53 101 5 41 83 137 7 43 89 139 1? 59 103 19 61 107 23 67 109 29 71 113 31 73 127 37 79 131 47 97 149 ress any key to continue .. .Explanation / Answer
Here is the C code for you. If you have any further queries, just get back to me.
#include <stdio.h>
#include <math.h>
int isPrime(int num)
{
int i;
for(i = 2; i <= (int)sqrt(num); i++)
if(num % i == 0)
return 0;
return 1;
}
int main()
{
int i, count = 0;
for(i = 2; i <= 100; i++)
{
if(isPrime(i))
{
count++;
printf("%i ", i);
if(count == 5)
{
printf(" ");
count = 0;
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.