Answer to Question #84201 in C for boshy

Question #84201
I want to write a program that finds prime numbers using a sieve of Eratosthenes method.
I must use (variable length array) vom Typ bool.
I wrote the following code, but unfortunately it does not work.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main()
{ int n,i;

printf("Enter the limit: ");
scanf("%d",&n);
int size = sizeof(A)/ sizeof(n);

prim(A,size);

for(i=2;i<n;i++)
{
if(A[i])
{
printf("\n%d",i);
}
}

return 0;
}
bool prim(int* A, int size)
{
int i,j;
for(i=2;i<n;i++)
A[i] = true;


for(i=2;i<n;i++)
{
for(j=i;i*j<n;j++)
{
A[i*j] = false;
}
}
}
can you help me please?
1
Expert's answer
2019-01-22T13:35:59-0500
The answer to the question is available in the PDF file https://www.assignmentexpert.com/https://www.assignmentexpert.com/homework-answers/programming-answer-84201.pdf

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS