Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A prime number is a natural number greater than 1 that has no positive divisors

ID: 1766236 • Letter: A

Question

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number Create a C++ program that utilizes nested for loop that asks the user for a number then the program should compile a list of all natural numbers from 2 to the mumber the user keyed in marking with a star the prime numbers only. . Asks the user for mumber 2. List all numbers from 2 to the user typed number. 3. Mark the Prime number with a stars leaving the composite numbers not labeled. 4. Stars should increment keeping track of the prime numbers found previously 5. In case no Prime numbers is found your program should notify the user 6. Make sure to check your program for values over 18o.

Explanation / Answer

if any error please leave a comment, i will correct it

#include<iostream>

using namespace std;

int main(){

int N ,i ,j, isprime, n;

cout<< " enter the value of N ;

cin>> N;

// for every number between 2 to N check whether it is prime or not

for(i=1; i<=N; i++){

isprime=0;

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

if(i%j==0){

isprime=1;

break;

}

}

if(isprime==0 && N!=1)

cout<< i <<"* ";

else

cout<< i <<" ";

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote