Question: Please write the c-code below in matlab. #include int main() { const int MAX = 1000; char number[MAX+1]; int index; int j; for(index = 0;

Please write the c-code below in matlab.

#include

int main()

{

const int MAX = 1000;

char number[MAX+1];

int index;

int j;

for(index = 0; index <= MAX; index++)

{

number[index]=1;

}

for(index = 2; index

<= MAX; index++)

{

if(number[index]==1)

{

for(j=2*index; j<=MAX; j=j+index)

{ number[j]=0;

if(index%2==0)

number[j]=0;

else

if(index%3==0)

number[j]=0;

else

if(index%5==0)

number[j]=0;

else

if(index%7==0)

number[j]=0;

}

}

}

printf("The following numbers are prime: ");

for(index=2;

index<=MAX; index++)

{

if(number[index]==1)

printf("%d ",index);

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!