• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

bad code

dejitaru

Banned
PHP stuff

<?
$y=1;
$x=1;
if(!$max)
{$max=200;}
while($x++<$max)
{
while($y++<$max)
{
if($q[$y]==0){$q[$x*$y]=1;}
}
$y=1;
}
for($x=0;$x<($max*2);$x++)
{if($q[$x]==0){echo "$x
";}}
?>

C++ interpretation doesn't work

#include <iostream>
using namespace std;
int main()
{
int max;
cout<<"need max\n";
cin>>max;

long y=2;
long x=2;
bool q[max];

for(x=0;x<max;x++){q[x]=0;}
x=2;

while(x++<max)
{
while(y++<max)
{
if(q[y]==0){q[x*y]=1;}
}
y=2;
}
for(x=0;x<(max*2);x++)
{
if(q[x]==0){cout <<x<<'\n';}}
}

It prints:
0
1

then exits
It's supposed to display prime numbers.

I removed the if from the for loop and changed (max*2) to max, still kills the app.
 
Back
Top