Data Structure -1 (Arrays) Class 12 Computer Science

Data Structure -1 (Arrays) 

Class 12 Computer Science

Picture 
1. Write a program to find the saddle points in a matrix. It is computed as follows:
  • Find out the smallest element in a row. The saddle point exists in a row if an element is the largest element in that corresponding column. For instance, consider the following matrix
         7   5  6
         10  2  3
         1   3   3

  • The saddle point results are listed below:
a) In row 1, saddle point exists at column 2.
b) In row 2, saddle point does not exist.
c) In row 3, saddle point does not exist.

 

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[5][5];
int m,n,pos=0;
cout<<"Enter matrix size (m X n) : ";
cin>>m;
cout<<" X ";
cin>>n;
int sad=0  ;
cout<<"\nEnter matrix elements: \n";
int min=100;
//----------------------------------INPUT-----------------------------------//
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
clrscr();
//----------------------------------SHOW------------------------------------//
cout<<"\nYour Entered Matrix : "<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cout<<a[i][j]<<"\t";
cout<<endl;
}
//----------------------------------OUTPUT----------------------------------//
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]<min)
{
min=a[i][j];
pos=j;
}
}
sad=min;
for(int k=0;k<m;k++)
{
if(sad<a[k][pos])
sad=a[k][pos];
}
if(min==sad)
cout<<"\nSaddle point in the row "<<i+1<<"= "<<min;
else
cout<<"\nNO Saddle point in the row." ;
min=a[i+1][0];
}
getch();
}

2. Write a user defined function in C++ to find and display the row sums of two-dimensional array.
 
     #include<iostream.h>
     #include<conio.h>
     void main()
     {   
     clrscr();
     int a[3][3];
     int i,j,s=0,sum=0;

     cout<<"Enter 9 elements of 3*3 Matrix \n";
     for(i=0;i<3;i++)
     for(j=0;j<3;j++)
     cin>>a[i][j];

     cout<<"Matrix Entered By you is \n";
     for(i=0;i<3;i++)
     {for(j=0;j<3;j++)
       cout<<a[i][j]<<" ";
        cout<<endl;
     }

     for(i=0;i<3;i++)
     {for(j=0;j<3;j++)
       s=s+a[i][j];
      cout<<"sum of row "<<i+1<<" is "<<s;
       s=0;
       cout<<endl;
     }
      
     getch();
     }

 

Comments

Related Posts

Computer Science Syllabus Class 11 2018-19 (NEW)

JEE Main 2019 result deaclerd! Check here

Sample Paper Science Class 10

Practice Paper Maths Class 10 Ch 2 Polynomials

Chapter 3 Deep Water Class 12