Please run and test the code please If you can make it very
Please run and test the code please. If you can, make it very simple to read, I am still learn. Thank you in advance
Write down a C program to generate a matrix (2-D Array) of integers in the range 1 to 100. The program should take the matrix dimensions (number of rows and number of columns) from the user. Print the matrix in such a way that only the prime numbers are printed. Print the character ‘*’ for the non-prime numbers. [Note that 1 is not a prime number].
Example: if the generated matrix is: 1 2 3 4 5 6 7 8 9 10 11 12
Print: * 2 3 * 5 * 7 * * * 11 *
Solution
program
#include<stdio.h>
 #include<conio.h>
 void main()
 {
    int matrix[100][100];
    int row, col,i,j,k;
    clrscr();
    printf(\"Enter the number of rows \");
    scanf(\" %d\",&row);
    printf(\"Enter the number of columns \");
    scanf(\" %d\",&col);
    printf(\"Enter the matrix elements\ \");
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            scanf(\" %d\",&matrix[i][j]);
        }
        printf(\"\ \");
    }
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            if(matrix[i][j]==1)
            {
            printf(\" * \");
            continue;
            }
           for(k=2;k<matrix[i][j];k++)
            {
                if(matrix[i][j]%k==0)
                {
                    printf(\" * \");
                    break;
                }
            }
            if(k==matrix[i][j])
            {
                printf(\" %d \",matrix[i][j]);
            }
        }
        printf(\"\ \");
    }
    getch();
 }
sample output
enter the number of rows 3
enter the number of columsn 3
enter the matrix elements 10 20 30 1 7 12 13 15 17
* * *
* 7 12
13 * 17


