Q1
#include
int main() {
int n = 100;
for (int i = 2; i < n; i = i+1) {
bool not_prime = false;
for (int j = 2; j < i && !not_prime; j = j+1)
if (i%j == 0)
not_prime = true;
if (!not_prime) {
printf("%d is a prime\n", i);
}
}
return 0;
}
這條程是什麼意思...??為甚麼可以噴出質數??
bool not_prime = false;是蝦米.....
Q2
#include <cstdio>
//52
int main () {
int n,i,t[1000],big[1]={0},i2=1;
scanf("%d",&n);
for(i2=i2;i2!=0;big[0]=0,i2=0)
{
for(i=0;i<n;i++)
{
scanf("%d",&t[i]);
}
for(i=0;i<n;i++)
{
if(t[i]>big[0])
big[0]=t[i];
}
for(i=0;i<n;i++)
{
if(big[0]==t[i])
t[i]=0;
}
for(i=0;i<n;i++)
{
printf("%d",t[i]);
if(i!=n-1)
printf(" ");
else
printf("\n");
}
for(i=0;i<n;i++)
if(t[i]!=0)
i2+=1;
}
}
這條......我打這樣第1層FOR迴圈不是可以執行很多次嗎.....為什麼只能1次.....
大大幫幫忙阿.......
This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.
留言列表