saving . . . saved Prime number has been deleted. Prime number has been hidden .
Prime number
Title
Question
How to display prime numbers

Advanced-Cpp Abstract-Class 02-03 min 30-40 sec 13-03-22, 8 a.m. moinshaik

Answers:

A meaningful program can be written as follows:
#include<iostream>
using namespace std;
int main()
{
    int i, chk=0, j;
    cout<<"Prime Numbers Between 1 to 100 are:\n";
    for(i=1; i<=100; i++)
    {
        for(j=2; j<i; j++)
        {
           if(i%j==0)
           {
               chk++;
               break;
           }
        }
        if(chk==0 && i!=1)
            cout<<i<<"\n";
        chk = 0;
    }
    return 0;
}
14-03-22, 10:58 a.m. hbammkanti


A meaningful program can be written as follows:
#include<iostream>
using namespace std;
int main()
{
    int i, chk=0, j;
    cout<<"Prime Numbers Between 1 to 100 are:\n";
    for(i=1; i<=100; i++)
    {
        for(j=2; j<i; j++)
        {
           if(i%j==0)
           {
               chk++;
               break;
           }
        }
        if(chk==0 && i!=1)
            cout<<i<<"\n";
        chk = 0;
    }
20-01-23, 9:56 p.m. nakul@7


#include <iostream>
using namespace std;

int main() {
    int n;
    cout << "Enter the upper limit: ";
    cin >> n;

    cout << "Prime numbers up to " << n << " are: ";
    for (int i = 2; i <= n; i++) {
        bool isPrime = true;
        for (int j = 2; j <= i / 2; j++) {
            if (i % j == 0) {
                isPrime = false;
                break;
            }
        }
        if (isPrime)
            cout << i << " ";
    }
    return 0;
}
14-07-25, 12:56 p.m. 240181601063@crescent.education


Log-in to answer to this question.