vendredi 26 novembre 2021

I need help please

in the image is the output i see details: it gives me zero primes in the array after running it. type of program: its a program that takes 2d array [n x m] then calculate how many prime numbers are there in the 2d array.

int isprime(int n)
{
    int k;
    if (n <= 1)
        return 0;
    for (k = 2; k <= (n / 2); k++){
        if (n % k == 0)
         return 0;
    }
    return 1;
}
}
int primecount(int x, int y, int a[x][y]){
    int r, c, count = 0;
    for(r = 0; r < x; r++) {
        for(c = 0; c < y; c++) {
            if(isprime(a[r][c]))
            {
                    count++;
            }
        }
    }
    return count;
}
int main()
{
    int n, m, i, j, z;
    printf("Enter the Number of Rows: ");
    scanf("%d", &n);
    printf("\n");
    printf("Enter the Number of Columns: ");
    scanf("%d", &m);
    printf("\n");
    int a[n][m];
    printf("Enter the elements of the array: \n");
    for(i = 0; i < n; i++)
    {
        for(j = 0; j < m; j++)
            scanf("%d", &a[i][j]);
    }
    z = primecount(n, m, a[n][m]);
    printf("\n");
    printf("The Number of Prime Numbers in the array is: %d", z);
    printf("\n");
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire