1.while
#include <iostream>
using namespace std;
int main () {
inti,j,n,m;
i=2;
while(i<101)
{
m=1,n=i/2;j=2;
while(j<=n)
if(i%j==0)
m=0;
break;
}
j++;
if(m)
cout<<i<<" ";
i++;
2.do....while
#include<iostream.h>
void main()
do
m=1;
n=i/2;
j=2;
while(j<=n);
while(i<101);
3.for
# include<iostream.h>
for(i=2;i<101;i++)
for(j=2;j<=n;j++)
1.while
#include <iostream>
using namespace std;
int main () {
inti,j,n,m;
i=2;
while(i<101)
{
m=1,n=i/2;j=2;
while(j<=n)
{
if(i%j==0)
{
m=0;
break;
}
j++;
}
if(m)
cout<<i<<" ";
i++;
}
}
2.do....while
#include<iostream.h>
void main()
{
inti,j,n,m;
i=2;
do
{
m=1;
n=i/2;
j=2;
do
{
if(i%j==0)
{
m=0;
break;
}
j++;
}
while(j<=n);
if(m)
cout<<i<<" ";
i++;
}
while(i<101);
}
3.for
# include<iostream.h>
void main()
{
inti,j,n,m;
for(i=2;i<101;i++)
{
m=1;
n=i/2;
for(j=2;j<=n;j++)
{
if(i%j==0)
{
m=0;
break;
}
}
if(m)
cout<<i<<" ";
}
}