1个回答
2013-09-25
展开全部
#include <iostream>
using namespace std;bool isprime_for(int n)
{
for (int i = 2; i<= n - 1; i++)
{
if (n % i == 0)
{
return false;
break;
}
else
return true;
}
}bool isprime_while(int n)
{
int i = 2;
while (i <= n - 1)
{
if (n % i == 0)
{
return false;
break;
}
else
return true;
i++;
}
}bool isprime_dowhile(int n)
{
int i = 2;
do
{
if (n % i == 0)
{
return false;
break;
}
else
return true;
i++;
}while(i <= n - 1);
}void main()
{
int n;
cin >> n;
cout << "for -> " << isprime_for(n) << endl;
cout << "while -> " << isprime_while(n) << endl;
cout << "do-while -> " << isprime_dowhile(n) << endl;
system("pause");
}
using namespace std;bool isprime_for(int n)
{
for (int i = 2; i<= n - 1; i++)
{
if (n % i == 0)
{
return false;
break;
}
else
return true;
}
}bool isprime_while(int n)
{
int i = 2;
while (i <= n - 1)
{
if (n % i == 0)
{
return false;
break;
}
else
return true;
i++;
}
}bool isprime_dowhile(int n)
{
int i = 2;
do
{
if (n % i == 0)
{
return false;
break;
}
else
return true;
i++;
}while(i <= n - 1);
}void main()
{
int n;
cin >> n;
cout << "for -> " << isprime_for(n) << endl;
cout << "while -> " << isprime_while(n) << endl;
cout << "do-while -> " << isprime_dowhile(n) << endl;
system("pause");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询