An integer is said to be prime if it is divisible by only 1 and itself. write a
ID: 3630979 • Letter: A
Question
An integer is said to be prime if it is divisible by only 1 and itself. write a function called prime() that takes in one integer number, return 1 if the number is prime and 0 otherwise. write a program that generates a random number between 1 to 1000( do research and find out how to do that) and calls function prime() to determine if it is prime or not.hi someone gave me this code but this in not what i want it gives a weired answer please modify it or write a new Unix C code. it prints out only 1 -100 numbers whereas i asked for 1 to 1000 also is there anyway i can ask the user to enter a number and then let the programe tell if it is prime or not instead letting the programme print all numbers.. thank you soooo much . below is the code i got earlier
#include <stdio.h>
#include <math.h>
int prime(int n) {
int i;
for ( i = 2; i <= sqrt(n); i++ ) {
if ( n % i == 0 ) {
return 0;
}
}
return 1;
}
int main() {
int i;
for (i = 0; i < 100; i++) {
printf("%d is %s ", i, prime(i) ? "prime" : "not prime");
}
return 0;
}
Explanation / Answer
This may help you.... /* take input from user for the prime() function */ #include #include int prime(int n) { int i; for ( i = 2; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.