#include<stdio.h>
#include<conio.h>
#include<string.h>
//typedef int BOOL;
//#define TRUE 1
//#define FALSE 0

int a[3][4];
int Prime(int *x);
void input();
void printOut();
void checkPrime();

int Prime(int *x)
{
        int i;
        for( i=2; i< (int)sqrt(*x); i++ )
        {
           if( *x%i == 0 )
           return 0;
        }
        return 1;   
}


void input()
{   int i,j;
    printf("Enter element for matrix: \n");
    for(i=0; i<3; i++)
        for(j=0; j<4; j++)
        {
                 printf("element a[%d][%d]: ",i,j);
                 scanf("%d",&a[i][j]);
        }
} 


void printOut()  
{
   int i,j;
   for(i=0; i<3; i++)
   {
      printf("\n");
      for(j=0; j<4; j++)
         printf(" %d ",a[i][j]);
   }  
}   

void checkPrime()
{
     int i,j;
     printf("\nMatrix after check Prime\n");
     for(i=0; i<3; i++)
     { 
     printf("\n");
     for(j=0; j<4; j++)
     {
       if( Prime(&a[i][j]) )
       printf(" %d(pr) ",a[i][j]);
       else 
       printf(" %d ",a[i][j]);
      }
     }
}

int main()
{
    input();
    printOut();   
    checkPrime();
    getch();
    return 0;
}

My source code does not work properly everytime.
I have not found where the mistake was
Please help me
Thanks a lot!

int Prime(int x)
{      
       int i;
        if (x==2) 
           return 0;
           else if (x < 2) 
                    return 1;
                 else
                 {
                    for( i=2; i<= (int)sqrt(x); i++ )
                    {
                       if( x % i == 0 )
                       return 1;
                    }
                    return 0; 
                 }  
}
void checkPrime()
{
     int i,j,k;
     printf("\nMatrix after check Prime\n");
     for(i=0; i<3; i++)
     { 
     printf("\n");
     for(j=0; j<4; j++)
     {
       printf(" %d",a[i][j]);
       if(! Prime(a[i][j]) )
       printf("(pr)",a[i][j]); 
     }
     }
}

Here is my improvement!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.