Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void inputArray2D(int [100][100],int,int);
- void printArray2D(int [100][100],int,int);
- void print1D(int[16]);
- void countArray(int[100][100],int,int,int[16]);
- int main()
- {
- ///Q:4.
- int arr2D[100][100],arr1D[16]={0},arr[100],r,c,n,m;
- cout<<"For Diagonal matrix, Row Column must be same here "<<endl;
- cout<<"input Row: ";
- cin>>r;
- cout<<"input Col: ";
- cin>>c;
- inputArray2D(arr2D,r,c);
- printArray2D(arr2D,r,c);
- cout<<endl;
- countArray(arr2D,r,c,arr1D);
- print1D(arr1D);
- }
- void inputArray2D(int arr[100][100],int row,int col)
- {
- cout<<"input 2D array"<<endl;
- for(int i=0;i<row;i++)
- {
- for(int j=0;j<col;j++)
- {
- // cin>>arr[i][j];
- arr[i][j]=rand()%16;
- }
- }
- }
- void printArray2D(int arr[100][100],int row,int col)
- {
- cout<<endl;
- for(int i=0;i<row;i++)
- {
- for(int j=0;j<col;j++)
- {
- cout<<arr[i][j]<<" ";
- }
- cout<<endl;
- }
- cout<<endl;
- }
- int returnDiagonalSize(int arr[100][100],int arr1D[100],int row,int col)
- {
- for(int i=0,j=0;i<row;i++,j++)
- {
- arr1D[i]=arr[i][j];/// This will store diagonal value in 1D array.
- }
- return row; ///here return the size
- }
- void print1D(int arr[20])
- {
- for(int i=0;i<16;i++)
- {
- cout<<i<<".";
- for(int j=0;j<arr[i];j++)
- {
- cout<<"*";
- }
- cout<<endl;
- }
- }
- void countArray(int arr[100][100],int row,int col,int arr1D[16])
- {
- for(int i=0;i<row;i++)
- {
- for(int j=0;j<col;j++)
- {
- arr1D[arr[i][j]]++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement