Question

Write a program that finds and prints all of the prime numbers between 3 and X (X is input from the user). A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 3, 5, 7, 11, 13, 17, …).

One way to solve this problem is to use a doubly nested loop (a loop inside another loop). The outer loop can iterate from 3 to N while the inner loop checks to see if the counter value for the outer loop is prime. One way to see if number n is prime is to loop from 2 to n-1 and if any of these numbers evenly divides n, then n cannot be prime. If none of the values from 2 to n-1 evenly divides n, then n must be prime.

Note: do **not** use break statements, and user
defined functions.

also tell how many prime numbers are there from 2 to n.

the language to be used is c++

Answer #1

**Program:**

#include<iostream>

using namespace std;

int main()

{

int X,i,j;

int count=0;

cout<<"Enter value of X: ";

cin>>X;

cout<<"\nPrime Numbers are : ";

for(i=3;i<=X;i++)

{

for(j=2;j<i;j++)

{

if(i%j==0)

{

//use goto instead of the break statement to jump to next

goto jump;

}

}

jump:

if(i==j)

{

cout<<i<<" ";

count++;

}

}

cout<<"\n\nThere are "<<count<<" prime numbers
from 3 to "<<X<<".";

return 0;

}

**Output:**

PYTHON 3
Write a program that prints the count of all prime numbers
between A and B (inclusive), where A and B are defined as
follows:
A = 21212
B = A + 5000
Just a recap on prime numbers: A prime number is any number,
greater or equal to 2, that is divisible ONLY by 1 and itself. Here
are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and
29.
Rules:
You should first...

Implement a nested for loop to jind the prime number up to n
numbers. print all the prime numbers up to N, we start one loop
from 2 to N and then inside the loop we check current number or
“num” is prime or not. To check if it is prime or not we again need
one nested loop. It is not an efficient way to check prime number
but it is simpler to understand the basic of looping in...

1) Write a C program to print the prime numbers from 1 to 100.
(A prime integer is any integer that can be divided evenly only by
itself and 1)
Requirement: Use an array to take the number from 1 to 100 and
another array to take the prime number.

I'm trying to write a nested loop in Mips Assembly that prints
out, for example, if user input x was 5:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
(spaces in between)
So far my code is :
li $v0, 5 #Ask for integer
syscall
move $t5, $v0
addi $t0, $zero, 0
For1:
slt $t1, $t0, $t5
beq $t1, $zero, Exit
add $s0, $s0, $t0
addi $t0, $t0, 1...

Write a program that asks the user to enter an odd number and
prints out a triangle pattern. For example, if the user enters 5,
the output is
note: There is one space between the numbers in each
line
1 3 5
1 3
1
If the user enters 9 the output is:
1 3 5 7 9
1 3 5 7
1 3 5
1 3
1
program language: C++

Design a program in Java that displays all of the prime numbers
from 1 through 100. The program should have a loop that calls the
isPrime() function.
11 Prime Numbers List (15 points)
Use CONSTANTS to set the maximum number in the table to
100 and the number of entries per row to
5.
Table of prime numbers from 1 to 100
1 2 3 5 7
11 13 17 19 23
29 31 37 41 43
47 53 59...

1) Write a java programming using a while
loop where you will add numbers and when you
press number 0 it will add all your
numbers and display the results.
Use Scanner object.
Steps:
1) Declare variables integer called sum which is equal to
zero
2) Declare Scanner object
3) Declare while condition where is true
4) Inside of that condition prompt the user to enter
the numbers
5) Declare variable integer called number and input
the number statement
6)...

- Write a python program which prints all the numbers between 1
and 100 that are divisible by 3.

draw flowchart of:
1-algorithm that asks the user to enter three numbers and
computes and prints out the largest number.
2- an algorithm that asks the for an integer N from the user.
The algorithm should find whether the number is positive,
negative,
or ZERO.
3-an algorithm that asks the user to enter a positive integer N.
You then need to calculate the sum of all values from 1 to N.

For C++:
a) Write a function is_prime that takes a positive integer X and
returns 1 if X is a prime number, or 1 if X is not a prime
number.
b) write a program that takes a positive integer N and prints
all prime numbers from 2 to N by calling your function is_prime
from part a.

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 4 minutes ago

asked 8 minutes ago

asked 26 minutes ago

asked 31 minutes ago

asked 35 minutes ago

asked 38 minutes ago

asked 45 minutes ago

asked 56 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago