1.已知n,计算n以内的所有素数之和sum 。
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
void writeinfile(int n);
void main()
{
int n,k,m,l,sum=0;
n=100;
/**********Program**********/
n=0;
for(m=1;m<=200;m++)
{
s=0;
for (k=1;k<m;k++);
{
if(m%k==0)
s=s+k;
}
if(s==m)
{
cout<<m<<endl;
n++;
}
cout<<n<<endl
/********** End **********/
writeinfile(sum);
}
void writeinfile(int n)
{
fstream myfile;
myfile.open(" f.txt" ,ios::out);
myfile<<n<<endl;
myfile.close();
}
#include <fstream.h>
#include <iostream.h>
int fun(int a[],int num)
{
/**********Program**********/
int i,j;
for(i=0;i<=9;i++)
if(num==a[i])
return 1;
else
return 0;
/********** End **********/
}
void main()
{
int a[10]={54,256,563,754,34,56,345,543,45,65};
int num = 46;
if (fun(a,num)==1)
cout <<" 找到!" <<endl;
else
cout <<" 没有找到!" <<endl;
void wwjt();
wwjt();
}
void wwjt()
{
int a[10]={54,256,563,754,34,56,345,543,45,65};
fstream myfile;
myfile.open(" out.txt" ,ios::out);
myfile<<fun(a,46)<<endl;
myfile<<fun(a,345)<<endl;
myfile.close();
}