Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++作业原C语言方法 #158

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions C++作业.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include<stdio.h>
void maopao(int a[],int n);
int main()
{
int a[20];
int o=0;
for(int i=100;i<=999;i++)
{
int c=i%10,b=(i-i%10)%10,a=i%100;
for(int x=2;x<i;x++)
{
if(i%x==0)
{
break;
}
else
{
for(int y=2;y<a*b*c;y++)
{
if((a*b*c)%y==0)
{
break;
}
else
{
for(int z=2;z<(a+b+c);z++)
{
if((a+b+c)%z==0)
{
break;
}
else
{
for(int m=2;m<(a*a+b*b+c*c);m++)
{
if((a*a+b*b+c*c)%m==0)
{
break;
}
else
{
a[o]=i;///Having problem.Debug it
o++;
}
}
}
}
}
}

}



}

}
printf("The number: %d\n",sizeof(a));
int sum=0;
for(int q=0;q<sizeof(a);q++)
{
sum += a[q];
}
printf("The sum: %d\n",sum);
maopao(a,sizeof(a));
int t=sizeof(a)-1;
printf("The biggest number: %d\n",a[t]);

return 0;
}



void maopao(int a[],int n)
{
int i,j;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if( a[j]>a[j+1] )
{
int temp;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}


}
30 changes: 30 additions & 0 deletions testfile/C++sort排序.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
char a[10]="AclRqsiFp";

for(int i=0;i<10;i++)
{
std::cout<<a[i]<<"\t";
}

std::cout<<"\n";
std::sort(a,a+10,std::greater<char>());

for(int i=0;i<10;i++)
{
std::cout<<a[i]<<"\t";
}




//system("pause");
return 0;
}




111 changes: 111 additions & 0 deletions testfile/寻找超级素数.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include<stdio.h>
int main()
{
int prime[1000];
int o=0;
for(int i=100;i<1000;i++) //100~999
{
if(i%2==0 || i%3==0 || i%5==0)
{
continue;
}

int q=0;
for(int j=2;j<i;j++)
{
if(i%j==0)
{
q=1;
break;
}
}
if(q==1)
{
continue;
}
else if(q==0)
{
prime[o]=i;
o++;
}

}
/* for(int v=0;v<o;v++)
{
printf("%d ",prime[v]);
}
printf("\n");*/
int superprime[50],t=0;
for(int u=0;u<o;u++)
{
int a,b,c;
a=prime[u]/100;
c=prime[u]%10;
b=(prime[u]-100*a-c)/10;
int x=a+b+c,y=a*b*c,z=a*a+b*b+c*c;//�����������

if(y==0)
{
continue;
}
int p1=0;
for(int j=2;j<x;j++)
{
if(x%j==0)
{
p1=1;
break;
}
}
if(p1==1)
{
continue;
}
else if(p1==0)
{
int p2=0;
for(int j=2;j<y;j++)
{
if(y%j==0)
{
p2=1;
break;
}
}
if(p2==1)
{
continue;
}
else if(p2==0)
{
int p3=0;
for(int j=2;j<z;j++)
{
if(z%j==0)
{
p3=1;
break;
}
}
if(p3==1)
{
continue;
}
else if(p3==0)
{
superprime[t]=prime[u];
t++;
}

}
}

}
for(int u1=0;u1<t;u1++)
{
printf("%d ",superprime[u1]);

}

return 0;
}