0
#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!

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by thebluestar
0
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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.