Geradot345

lb6.1(

Oct 28th, 2020
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. //Щеглов В.А. 19ВИ1
  2. #include <iostream>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int nechet_stolb(int n,int m,int** a){
  8. int i,j,nech_stolb=-1,b=0;
  9. for(j=0;j<n;j++){
  10. for(i=0;i<m;i++){
  11. if(a[i][j]%2==1) b++;
  12. }
  13. if(b==m) {nech_stolb=j+1;
  14. break;
  15. }
  16. b=0;
  17. }
  18. return nech_stolb;
  19. }
  20.  
  21. int main()
  22. {
  23. setlocale(LC_ALL, "Russian");
  24. int i,n,m,b,j;
  25. b=0;
  26. cout<<"Введите кол-во строк в матрице: ";
  27. cin>>m;
  28. cout<<"Введите кол-во столбцов в матрице: ";
  29. cin>>n;
  30. int** a=new int*[m];
  31. for(i=0;i<m;i++){
  32. a[i]=new int[n];
  33. }
  34. cout<<"Все элементы матрицы:\n";
  35. for(i=0;i<=m-1;i++){
  36. for(j=0;j<n;j++){
  37. a[i][j]=rand()%10000;
  38. cout<<setw(6)<<a[i][j];
  39. }
  40. cout<<endl;
  41. }
  42. b=nechet_stolb(n,m,a);
  43. if(b==-1)cout<<"Нет ни одного столбца со всеми нечётными элементами"; else
  44. cout<<"Номер первого столбца со всеми нечётными элементами="<<b;
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment