I am missing something but I can't find what it is. I have also been given a input2.c file and it has a print_prim function which I am not allowed to change.
For n=10 it is always printing
4, 5, 7, 9,
I know there is an i+2 in print_prim function but I can't solve it. Again, I am not allowed to change print_prim function. Can anyone see what am i missing?
main.c
#include <stdio.h>
#include <stdlib.h>
#include "input2.h"
int main() {
int n = lese_int();
int laenge = n-1;
int *array;
array = malloc(sizeof(int) * laenge);
for (int i = 2; i <= n; i++) {
array[i] = 1;
}
for(int i=0;i<=n;i++) {
if(array[i] == 1){
for(int j = i ; i*j <= n ; j++){
array[i*j] = 0;
}
}
}
print_prim(array, laenge);
free(array);
return 0;
}
print_prim function
void print_prim(int *array, int laenge) {
for (int i=0; i<laenge; i++) {
if (array[i] == 1) {
printf("%d, ", i+2);
}
}
printf("\n");
}