In: Computer Science
Part 1. Call your program by the name: "program_001_print_primes_between_a_and_b".
Input two integers a and b. Your program must print all the prime numbers between a and b. You must use the function int is_prime(int n) in your solution. The is_prime( ) function takes an integer n as input, and returns 1 if n is prime and 0 if n is prime, i.e., if n is composite.
NOTE: Upload ONLY your source code. Do not upload the entire executable or the solution file/folder.
#include <stdio.h>
int is_prime(int n);
int main() {
int low, high, i, flag,n;
printf("Enter two numbers(intervals)\n");
scanf("%d %d", &low, &high);
printf("Enter the value to check for prime or not : ");
scanf("%d",&n);
printf("Prime numbers between %d and %d are: ", low, high);
while (low < high) {
flag = 0;
if (low <= 1) {
++low;
continue;
}
for (i = 2; i <= low / 2; ++i) {
if (low % i == 0) {
flag = 1;
break;
}
}
if (flag == 0)
printf("%d ", low);
++low;
}
int result=is_prime(n);
if(result==1)
{
printf("\nThe given number is prime and reutrned %d",result);
}
else
{
printf("\nThe given number is not prime and reutrned %d",result);
}
return 0;
}
int is_prime(int n)
{
int i=0,count=0;
for(i=2;i<n/2;i++)
{
if(n%i==0)
{
count++;
}
}
if(count>0)
{
return 0;
}
else
{
return 1;
}
}
Here is the function that asks the user to enter two values adn then print the prime nummber in range of that two number and also it asks the user to enter an integer to check prime or not and print wheter the number is prime or not by calling a function if the number is prime it will return 1 or else 0 and the program is in C LANGUAGE and screenshot of the output is given below
SCREENSHOT OF THE OUTPUT :