Advertisement
monyca98

2016august sub2 pr5

Mar 1st, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. void citire(int &n, int &m, int a[][50])
  5. {
  6.     do
  7.     {
  8.         cout << "n="; cin >> n;
  9.         cout << "m="; cin >> m;
  10.     } while (n < 3 || n>100);
  11.     cout << "dati elementele matricei:";
  12.     for (int i = 0; i < n; i++)
  13.         for (int j = 0; j < m; j++)
  14.             cin >> a[i][j];
  15. }
  16. bool exista(int a[][50], int n, int m,int x)
  17. {
  18.     int i = 0;
  19.     for (int j = 0; j < m; j++)
  20.         if (a[i][j] == x)
  21.             return true;
  22.     int j = n - 1;
  23.     for (int i = 0; i < n; i++)
  24.         if (a[i][j] == x)
  25.             return true;
  26.     i = n - 1;
  27.     for (int j = 0; j < m; j++)
  28.         if (a[i][j] == x)
  29.             return true;
  30.     j = 0;
  31.     for (int i = 0; i < n; i++)
  32.         if (a[i][j] == x)
  33.             return true;
  34.     return false;
  35.  
  36.  
  37. }
  38. int main()
  39. {
  40.     int a[50][50], n, m, x;
  41.     citire(n, m, a);
  42.     cout << "x="; cin >> x;
  43.     if (exista(a, n, m, x))
  44.         cout << "da";
  45.     else
  46.         cout << "nu";
  47.     cout << endl << endl;
  48.     system("pause");
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement