[go: up one dir, main page]

0% found this document useful (0 votes)
57 views5 pages

Write A Program To Find The Saddle Point of The Matrix.: C++ Practical

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 5

C++ Practical

Program-1

Write a program to find the saddle point of the matrix.


#include<iostream.h>
#include<conio.h>
saddlepoint(int a[10][10],int row,int col);

void main()
{
int a[10][10],i,j;
clrscr();
cout<<"Enter the matrix elements\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>a[i][j];
}
}
saddlepoint(a,3,3);
getch();
}

saddlepoint(int a[10][10],int row,int col)


{
int big[10],small[10],i,j,max,min;
for(i=0;i<row;i++)
{
big[i]=a[i][0];
for(j=1;j<col;j++)
{
if(a[i][j] < big[i])
{
big[i] = a[i][j];
}
}
}
for(j=0;j<col;j++)
{
small[j]=a[0][j];
for(i=1;i<row;i++)
{
if(a[i][j] > small[j])
{
1 Roll No: 00513704410
C++ Practical

small[j]=a[i][j];
}
}
}
max=big[0];
for(i=1;i<row;i++)
{
if(big[i] > max)
{
max = big[i];
}
}
min=small[0];
for(j=1;j<col;j++)
{
if(small[j] < min)
{
min = small[j];
}
}
if(max==min)
{
cout<<"\n\n\n\t\t\tTHE SADDLE POINT IS -->"<<max<<endl;
}
else
{
cout<<"\n\n\n\nNO SADDLE POINT";
}
getch();
return 0;
}

Output:

2 Roll No: 00513704410


C++ Practical

Program-2

Write a program to find the position of a substring within string (using pointers).
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
void locate(char *,char *);
void main()
{
char s1[50],s2[20];
clrscr();
cout<<"\nEnter the main String:";
gets(s1);
cout<<"\nEnter the substring to be searched in the main string:";
gets(s2);
locate(s1,s2);
getch();
}
void locate(char *mainstr,char *substr)
{
int i,j,flag=0,a,pos;
int l1=strlen(mainstr);
int l2=strlen(substr);
for(i=0;i<=l1-l2;i++)
{
if(mainstr[i]==substr[0])
{
pos=i;j=0;
while(mainstr[i]==substr[j])
{
j++;
i++;
}
if(j>=strlen(substr))
{
flag=1;
break;
}
}
}
if(flag)
cout<<"\nSub string is present at position "<<pos+1;
else

3 Roll No: 00513704410


C++ Practical

cout<<"\nSub string is not present in main string.";


getch();
}

Output:

4 Roll No: 00513704410


C++ Practical

arrial
narrow:14above 15 below

5 Roll No: 00513704410

You might also like