Question

In C program #include<stdio.h> The first 11 prime integers are 2, 3, 5, 7, 11, 13,...

In C program

#include<stdio.h>

The first 11 prime integers are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, and 31.

A positive integer between 1 and 1000 (inclusive), other than the first 11 prime integers, is prime if it is not divisible by 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, and 31.

Write a program that prompts the user to enter a positive integer between 1 and 1000 (inclusive) and that outputs whether the number is prime.

If the number is not prime, then output all the numbers, from the list of the first 11 prime integers, which divide the number.

Example Output:

Enter an integer between 1 and 1000 (inclusive): 62

62 is divisible by 2, 31.
62 is not prime.

Enter an integer between 1 and 1000 (inclusive): 1206

You must enter a number between 1 and 1000 (inclusive).

Enter an integer between 1 and 1000 (inclusive): -1

You must enter a number between 1 and 1000 (inclusive).

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int main(){
   int n, i;
   
   while(1){
      printf("Enter an integer between 1 and 1000 (inclusive): ");
      scanf("%d",&n);
      
      if(n == -1){
         break;
      }     
      else if(n < 1 || n>1000){
         continue;
      }
      else{
         printf("%d is divisible by ", n);
         for(i = 2;i<n;i++){
            if(n%i== 0){
               printf("%d ",i);
            }
         }
         if(i == n){
            printf("%d is not prime\n", n);
         }
         else{
            printf("None\n");
            
            printf("\n%d is prime\n", n);
         }
      }
   }
   
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
In C program #include<stdio.h> The first 11 prime integers are 2, 3, 5, 7, 11, 13,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • use simple C++ please Exercise 3: Write a program that reads a positive number and checks...

    use simple C++ please Exercise 3: Write a program that reads a positive number and checks if the number can be expressed as a sum of two prime numbers. If yes, write all possible ways of expressing the number as sum of primes. Note: n is a prime if it is divisible only by 1 and itself, hence not divisible by any integer in the range from 2 to sqrt(n), both inclusive. Write a function is Prime that take a...

  • in java the program must contain the main method and example( the number 50 should be...

    in java the program must contain the main method and example( the number 50 should be the input) must be included in the main method to check the correctness of your programs. Create a GUI program to let user enter a positive integer n through the first window, and then your program prints out all the prime integers within the range [1, n) through the second window. Your program should contain two windows in total. Below are two example pictures:...

  • Program Requirements First, find all the prime numbers between 2 and a user-inputted number from the...

    Program Requirements First, find all the prime numbers between 2 and a user-inputted number from the console (inclusive). The identified prime numbers must be stored in an array . The inputted number should be between 0 and 1000 (inclusive). array is large enough to o Make sure your hold all the prim e numbers. Dynamic memory allocation is not required for this assignment, so you can have unused space in your array Make sure you can handle the cases of...

  • The following function is_prime() is not a very efficient prime number test: #include <stdio.h> int is_prime(int...

    The following function is_prime() is not a very efficient prime number test: #include <stdio.h> int is_prime(int n) { int d; for (d = 2; d < n; d++) { if (!(n % d)) return 0; } return 1; } int main() { if (is_prime(7)) printf("Seven is Prime!\n");    return 0; } It is unnecessary to divide n by all numbers between 2 and n - 1 to determine if n is prime. Only divisors up to and including  need to be...

  • Is Prime Number In this program, you will be using C++ programming constructs, such as functions....

    Is Prime Number In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter a positive integer, and outputs a message indicating whether the integer is a prime number. If the user enters a negative integer, output an error message. isPrime Create a function called isPrime that contains one integer parameter, and returns a boolean result. If the integer input is a prime number, then this function returns...

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • I must create a Loop in C++ that will print all prime numbers less than the...

    I must create a Loop in C++ that will print all prime numbers less than the number entertered by the user. 1. Accept the upper limit from the user (as an integer). (5 points) 2. Make sure the number is positive. If it is not, terminate the program. (5 points). 3. Go from 1 to the number. If you happen to find a number that is prime, print it. (35 points) example: Enter the upper limit: 25 The prime numbers...

  • Write a java program to print all the prime numbers below a certain given number. A...

    Write a java program to print all the prime numbers below a certain given number. A prime number is defined as a number that can only be divided by 1 and itself. Requirements: 1. Accept the upper limit from the user as an integer. 2. You can assume the user input will be positive and smaller than INT MAX 3. Go from 1 to the number. If you happen to find a number that is prime, print it. The input...

  • write a Matlab program ( solve the three questions). please use array and create your own...

    write a Matlab program ( solve the three questions). please use array and create your own function to check primality Question 1 : [10 points) Write a MATLAB program that will store all the first 1000 prime numbers in an array variable named arr_of_primes. Please note that a prime number is a positive integer that is bigger than or equal to 2 which is divisible only by 1 and itself. Examples of the first 8 primes are: 2, 3, 5,...

  • 1) (5 points) The following program is used to display numbers between two intervals include stdio.h...

    1) (5 points) The following program is used to display numbers between two intervals include stdio.h define true 1 define false 0 5 void prime (int low, int high) int i -o, flag-0 ; printf ("Prime numbers between %d and %d are: ", low, high); while (low <high) 10 flag false; 12 13 for (i 0; i <-low/2; ++i) - 15 16 17 if(low % ?--0) flagtrue: break; 19 20 21 if (flagtrue ) 23 24 25 26 27 28...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT