Advertisement
Nagy_Szabolcs

alkalmazasok2 2

Sep 21st, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. void beolvasas(int boole_mat[][50], int& n){
  7.     ifstream fin("boole.txt");
  8.     fin >> n;
  9.  
  10.     for(int i = 0; i < n; i++){
  11.         for(int j = 0; j < n; j++)
  12.             fin >> boole_mat[i][j];
  13.     }
  14. }
  15. void kiiratas(int boole_mat[][50], int n){
  16.     for(int i = 0; i < n; i++){
  17.         for(int j = 0; j < n; j++)
  18.             cout << boole_mat[i][j] <<' ';
  19.         cout << endl;
  20.     }
  21. }
  22.  
  23. void p_e_mat_tolt(int p_e_mat[][50],int boole_mat[][50],int n){
  24.     int index = 0;
  25.  
  26.     for(int i = 0; i < n; i++){
  27.         for(int j = 0; j < n; j++){
  28.             if(boole_mat[i][j]){
  29.                 p_e_mat[i][index] = 1;
  30.                 p_e_mat[j][index++] = 1;
  31.             }
  32.         }
  33.     }
  34. }
  35.  
  36. void p_e_mat_ki(int p_e_mat[][50],int n, int m){
  37.     for(int i = 0; i < n; i++){
  38.         for(int j = 0; j < m; j++)
  39.             cout << p_e_mat[i][j] <<' ';
  40.         cout << endl;
  41.     }
  42. }
  43.  
  44. int elek_szama(int boole_mat[][50], int n){
  45.     int m = 0;
  46.  
  47.     for(int i = 0; i < n; i++){
  48.         for(int j = 0; j < n; j++)
  49.             if(boole_mat[i][j]) m++;
  50.     }
  51.  
  52.     return m;
  53. }
  54.  
  55. int main() {
  56.     int boole_mat[50][50], n;
  57.     beolvasas(boole_mat, n);
  58.     kiiratas(boole_mat,n);
  59.  
  60.     cout << endl << endl;
  61.     int p_e_mat[50][50] = {}, m;
  62.     m = elek_szama(boole_mat, n);
  63.     p_e_mat_tolt(p_e_mat, boole_mat, n);
  64.     p_e_mat_ki(p_e_mat, n, m);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement