Question #1407

Make a C program that will generate Parkside's Triangle. Given any side and any seeds

Expert's answer

`int i;`

int lowerlimit;

int

upperlimit;

onSelfEvent(load){

lowerlimit=9;

upperlimit=20;

for(i=lowerlimit;i<=upperlimit;i++){

if

(i%2==0){

_root.Show(i);

}

}

}

int j;

int N;

int

primes = 0;

int nn=0;

int left=0;

int right=0;

function Show(number

) {

isprime = new Array;

N =

number;

for(j=2;j<N;j++){

isprime[j] =

"1";

}

}

for(j=2;j<=N;j++){

if(i*i<N){

if(isprime[j]=="1"){

for(l=j;l<=N;l++){

isprime[i

* j] = "0" ;

}

}

}

}

for(j=2;j<N;j++){

if(isprime[j]=="1"){

primes =

primes + 1;

}

}

list = new Array[primes]

for(j=0;j<N;j++){

if(isprime[j]=="1"){

nn = nn + 1;

list[nn] =

"i";

}

}

left = 0;

right = primes - 1;

while (left

<= right){

if(list[left] + list[right] = N){

break;

else if

(list[left] + list[right] < N){

left = left + 1;

else

right = right

- 1;

}

}

}

if (list[left] + list[right] = N){

trace(N + " = " +

list[left] + " + " + list[right]);

}

else{

trace(N + " not expressible

as sum of two primes");

}

return 0;

}

Learn more about our help with Assignments: C++

## Comments

## Leave a comment