-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2DFUNPRI.CPP
More file actions
40 lines (38 loc) · 805 Bytes
/
2DFUNPRI.CPP
File metadata and controls
40 lines (38 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//Function - To display the prime numbers in the entered matrix
#include<iostream.h>
#include<conio.h>
void prime (int a[][30],int,int);
void main()
{int a[30][30],p,q,i,j;
clrscr();
cout<<"Enter the dimension of the matrix "<<endl;
cin>>p>>q;
cout<<"Enter the elements of the matrix "<<endl;
for(i=0;i<p;i++)
{ for(j=0;j<q;j++)
cin>>a[i][j];
}
cout<<"The matrix you entered is "<<endl;
for(i=0;i<p;i++)
{ cout<<endl;
for(j=0;j<q;j++)
cout<<'\t'<<a[i][j];
}
prime(a,p,q);
getch();
}
void prime (int a[][30],int p,int q)
{int i,j,k,flag=1;
cout<<endl<<"The prime numbers in the matrix are ";
for(i=0;i<p;i++)
{ for(j=0;j<q;j++)
{flag=1;
for(k=2;k<a[i][j];k++)
{if((a[i][j]%k)==0)
flag=0;
}
if(flag==1)
cout<<endl<<'\t'<<a[i][j];
}
}
}