Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- /*
- Liczby naturalne a,b s¹ komplementarne je¿eli ich suma jest liczb¹
- pierwsz¹. Dana jest tablica typu tab=array[1..max,1..max] of integer;
- wype³niona liczbami naturalnymi. Proszê napisaæ procedurê, która zeruje
- element nie posiadaj¹ce liczby komplementarnej
- */
- using namespace std;
- const int N = 3;
- void print_table(int tab[N][N]);
- bool isPrime(int n);
- void set_table(int tab[N][N]);
- int main()
- {
- int tab[N][N];
- set_table(tab);
- bool flag = true;
- int licznik = 0;
- for(int i=0; i<N; i++)
- {
- for(int j=0; j<N; j++)
- {
- for(int k=i+1; k<N; k++)
- {
- for(int m=j+1; m<N; m++)
- {
- if(!isPrime(tab[i][j] + tab[k][m]))
- {
- licznik++;
- if(licznik == N*N){
- tab[i][j] = 0;
- }
- }
- }
- }
- }
- }
- cout<<endl<<endl;
- print_table(tab);
- return 0;
- }
- bool isPrime(int n)
- {
- if(n < 2)
- return false;
- for(int i=2; i*i <= n; i++)
- {
- if(n%i == 0)
- return false;
- }
- return true;
- }
- void set_table(int tab[N][N])
- {
- srand(time(NULL));
- for(int i=0; i<N; i++)
- {
- for(int j=0; j<N; j++)
- {
- tab[i][j] = rand() % 50 + 1;
- cout<<tab[i][j]<<"\t";
- }
- cout<<endl<<endl;
- }
- }
- void print_table(int tab[N][N])
- {
- for(int i=0; i<N; i++) // wyswietlanie tablicy
- {
- for(int j=0; j<N; j++)
- {
- cout<<tab[i][j]<<"\t";
- }
- cout<<endl<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement