Question

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...

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.

Solutions

Expert Solution

#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 :


Related Solutions

PART 1: WRITE A PROGRAM THAT TAKES IN TWO INTEGERS VALUE N AND M (USER INPUT)...
PART 1: WRITE A PROGRAM THAT TAKES IN TWO INTEGERS VALUE N AND M (USER INPUT) AND CALCULATES THE NTH FIBONACCI SUM USING RECURSION. EXAMPLE: OLD VERSION 0,1,1,2,3.. USING USER INPUT: 0, N, M ,N+M, (N+M)+M PART 2: WRITE THE SAME PROGRAM USING USER INPUT BUT USING A LOOP IN STEAD OF RECURSION. PYTHON
Q-1) Write a program that mimics a calculator. The program should take as input two integers...
Q-1) Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator, and the result. For division, if the denominator is zero, output an appropriate message. Some sample outputs follow: 3 + 4 = 7 13 * 5 = 65
Question 1: 5pts Write a program to receive two integers as user input and then print:...
Question 1: 5pts Write a program to receive two integers as user input and then print: Sum Difference Product Average Maximum of the two Minimum of the two You may use the min and max functions declared in the math class. ********************************************************************************** Question 2: 10pts An online bank wants you to create a program that will show a prospective customer, how the deposit will grow. Your program should read the initial balance and the annual interest rate. Interest rate is...
Question 1: Write a program to receive two integers as user input and then print: Sum...
Question 1: Write a program to receive two integers as user input and then print: Sum Difference Product Average Maximum of the two Minimum of the two You may use the min and max functions declared in the math class. ********************************************************************************** Question 2: An online bank wants you to create a program that will show a prospective customer, how the deposit will grow. Your program should read the initial balance and the annual interest rate. Interest rate is compounded monthly....
Part 1 Write a program that displays a frame containing two labels that display your name,...
Part 1 Write a program that displays a frame containing two labels that display your name, one for your first name and one for your last. Experiment with the size of the window to see the labels change their orientation to each other. USE FIRST NAME: Aya LAST NAME: KAYED. SEND THE CODE IN THE EXACT FORMAT FOR JAVA ECLIPSE. I WILL COPY AND PASTE THE CODE SO I CAN RUN IT. Part 2 Propose and solve your own digital...
Create a program that asks the user for two positive integers. If the user's input for...
Create a program that asks the user for two positive integers. If the user's input for either integer is not positive (less than or equal to 0), re-prompt the user until a positive integer is input. You may assume that all inputs will be integers. Print out a list, ascending from 1, of all divisors common to both integers. Then, print out a message stating whether or not the numbers are "relatively prime" numbers. Two positive integers are considered relatively...
Write a program whose input is two integers, and whose output is the first integer and...
Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. import java.util.Scanner; public class LabProgram {...
Write a program that uses two identical arrays of at least 25 integers. It should call...
Write a program that uses two identical arrays of at least 25 integers. It should call a function that uses the bubble sort algorithm to sort one of the arrays in descending order. The function should keep a count of the number of exchanges it makes. The program then should call a function that uses the selection sort algorithm to sort the other array. It should also keep count of the number of exchanges it makes. Display these values on...
Create a c++ program to compute the product of two integers. call create the following functions:...
Create a c++ program to compute the product of two integers. call create the following functions: 1. getNum - to accept only positive numbers && will call computeProd. 2.computeProd - to compute the product of the numbers & will call the function displayProduct. 3. displayProduct - to display the product. Call the function getNum in the main function. Compute the product w/o using the multiplication operator(*). using #include <iostream> only
Write a C++ program to do the following USING ARRAYS 1) input 15 integers (input validation...
Write a C++ program to do the following USING ARRAYS 1) input 15 integers (input validation , all numbers must be between 0 and 100) 2) find the largest number 3) Find the Smallest Number 4) Find the Sum of all numbers in the Array Display: as per the user's section (menu using switch or if else ) Largest Number Smallest Number Sum of all numbers the original Array DO NOT USE METHODS OR FUNCTIONS Submit: Source code (C++) output...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT