/*
* Copyright (c)2013, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称: array.cpp
* 作 者: 李中意
* 完成日期:2014 年 1 月 22 日
* 版本号: v1.0
* 输入描述:无
*/
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int a,b,c,k,i,n;
bool prime;
cout<<"请输入两个数"<<endl;
cin>>a>>b;
cout<<a<<"和"<<b<<"之间的素数有:"<<endl;
for(c=a;c<=b;c++)
{
k=int(sqrt(c));
for(i=2;i<=k;i++)
{
if(c%i==0)
{
prime=false;
break;
}
if(prime)
{
cout<<setw(5)<<c;
n=n+1;
}
if(n%5==0)
cout<<endl;
}
cout<<endl;
}
cout<<"其间的素数共有:"<<n<<"个"<<endl;
system("pause");
return 0;
}
编译的时候一个错误和警告都没有,但是运行起来就不对。不知道问题出在了哪里