Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A prime number is a positive integer that has factors of 1 and itself. The first

ID: 3813173 • Letter: A

Question

A prime number is a positive integer that has factors of 1 and itself. The first few prime numbers are: 2, 3, 5, 7, 11, 13, 17, 19. You will write a Boolean function that takes a positive input if the input is prime and False if the integer as and returns "True" input is not prime and "False" if the input is not prime. Using this function. Write a program that will find the first 100 prime numbers. Note that this does not say the prime numbers between 1 and 100. There will be suitable messages explaining the output which will be a list of the numbers and the message Prime or not prime. This output will be in the form of a file by name prime dat. You may wish to do some formatting of the output to make the file more compact.

Explanation / Answer

#include <stdio.h>
#include "genlib.h" //Different header files are applicable in different compilers
#include "simpio.h"
#include "math.h"


bool primenumber (int num); //calling the function


main()
{
int count,number,i;
printf("ENTER THE TOTAL PRIME NUMBERS YOU WANT");
scanf("%d",&count);
for (i=2; i<=count; i++)
{
if (primenumber(i)) //checks for every primenumber between 2 and count
{
printf("%d ",i);
}

}
}


bool primenumber (int num) //function definition
{
int i;
for (i=2; i<=sqrt(num); i++)
{
if ((num % i) == 0)
{
return false;
}
}
return true;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote