Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void inputArray2D(int [100][100],int,int);
  6. void printArray2D(int [100][100],int,int);
  7. void print1D(int[16]);
  8. void countArray(int[100][100],int,int,int[16]);
  9.  
  10. int main()
  11. {
  12. ///Q:4.
  13.  
  14. int arr2D[100][100],arr1D[16]={0},arr[100],r,c,n,m;
  15.  
  16. cout<<"For Diagonal matrix, Row Column must be same here "<<endl;
  17. cout<<"input Row: ";
  18. cin>>r;
  19. cout<<"input Col: ";
  20. cin>>c;
  21. inputArray2D(arr2D,r,c);
  22. printArray2D(arr2D,r,c);
  23. cout<<endl;
  24.  
  25. countArray(arr2D,r,c,arr1D);
  26.  
  27. print1D(arr1D);
  28. }
  29.  
  30. void inputArray2D(int arr[100][100],int row,int col)
  31. {
  32. cout<<"input 2D array"<<endl;
  33. for(int i=0;i<row;i++)
  34. {
  35. for(int j=0;j<col;j++)
  36. {
  37. // cin>>arr[i][j];
  38. arr[i][j]=rand()%16;
  39. }
  40. }
  41. }
  42.  
  43. void printArray2D(int arr[100][100],int row,int col)
  44. {
  45. cout<<endl;
  46. for(int i=0;i<row;i++)
  47. {
  48. for(int j=0;j<col;j++)
  49. {
  50. cout<<arr[i][j]<<" ";
  51. }
  52. cout<<endl;
  53. }
  54. cout<<endl;
  55. }
  56.  
  57.  
  58. int returnDiagonalSize(int arr[100][100],int arr1D[100],int row,int col)
  59. {
  60.  
  61. for(int i=0,j=0;i<row;i++,j++)
  62. {
  63. arr1D[i]=arr[i][j];/// This will store diagonal value in 1D array.
  64. }
  65. return row; ///here return the size
  66.  
  67.  
  68. }
  69. void print1D(int arr[20])
  70. {
  71. for(int i=0;i<16;i++)
  72. {
  73. cout<<i<<".";
  74. for(int j=0;j<arr[i];j++)
  75. {
  76. cout<<"*";
  77. }
  78. cout<<endl;
  79. }
  80. }
  81.  
  82. void countArray(int arr[100][100],int row,int col,int arr1D[16])
  83. {
  84.  
  85. for(int i=0;i<row;i++)
  86. {
  87. for(int j=0;j<col;j++)
  88. {
  89. arr1D[arr[i][j]]++;
  90. }
  91. }
  92.  
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement