初学者,确实不懂,请大神指教。
c++吧
全部回复
仅看楼主
level 1
输出2到99的素数,要求每输出五个换行一次。
2012年11月26日 07点11分 1
level 1
要求用C++语言编写,谢谢。
2012年11月26日 07点11分 2
level 9
我也大一的新生 这个还是比较简单吧 我们现在学的是c语言
lz
呢?
2012年11月26日 07点11分 3
我学的是C++语言啊。郁闷。指教一下我吧。
2012年11月26日 07点11分
C语言我就会 c++就不知道了
2012年11月26日 07点11分
level 1
怎么没人啊。
2012年11月26日 07点11分 4
level 1
我很用心学了,但是之前没接触过,要怎么样学啊?
2012年11月26日 07点11分 5
level 4
include因为有些这个里不用的,没给出。。其实这东西不会的网上看看资料,自己先有个逻辑写出来就简单了
int _tmain(int argc, _TCHAR* argv[])
{
int iPrime[100] = {0};
int iCount = 0;
for (int i = 2;i != 100;i++)
{
if (IsPrime(i) == true)
{
iPrime[iCount] = i;
iCount++;
}
}
cout<<"prime between 2~99:"<<endl;
for (int i = 0;i != (int)iCount/5;i++)
{
for (int j = 0;(j != 5)&&(i*5+j != iCount);j++)
{
cout<<iPrime[i*5+j]<<" ";
}
cout<<endl;
}
system("pause");
return 0;
}
bool IsPrime(int i)
{
for (int j = 2;j != i;j++)
{
if (i%j == 0)
{
return false;
}
}
return true;
}
2012年11月26日 07点11分 6
还是不太懂。
2012年11月26日 09点11分
首先要知道什么是素数,就是除了任何比它小的数余数都不是零,然后把这句话变成逻辑表达式
2012年11月26日 09点11分
level 10
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
void main()
{
int i,n,m,k=0;
for(n=2;n<=99;n++)
{
m=(int)sqrt(n);
for(i=2;i<=m;i++)
{
if(n%i==0)
{
break;
}
}
if(i==m+1)
{
cout<<setw(5)<<n;
k++;
if(k%5==0) cout<<'\n';
}
}
cout<<endl;
}
2012年11月26日 17点11分 7
谢谢。
2012年11月27日 04点11分
1