Prime number
Title
Question
How to display prime numbers
Advanced-Cpp Abstract-Class 02-03 min 30-40 sec
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;
}
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;
}
Login to add comment