Project 5 Concepts tested by this program: 1. Learn to organize code within a fu
ID: 3687535 • Letter: P
Question
Project 5 Concepts tested by this program: 1. Learn to organize code within a function 2. Learn to pass data to and return Boolean data from function 3. Use of loop 4. Use file processing Program Prime Numbers A prime number is an integer that is greater than 1 and 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. Demonstrate the function in a complete program that reads in an integer that is less than 3001 stores a list of all the prime numbers from 2 through that number in a file named "PrimeList.txt" and to the standard output.
Explanation / Answer
Java programming code
-----------------------------
C program to Check Prime Number
---------------------
C program for prime number using function
--------------------
/*C program to print 1 to 3100 prime numbers*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,n,div,p;
printf("Enter any number: ");
scanf("%d", &num);
for(n=2; n<=num; n++)
{
for(div=2; div<n; div++)
{
if(n%div==0)
{
p=0;
break;
}
p=1;
}
if(p)
printf(" %d",n);
}
getch();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.