Binary Search
{
int a[180][180], i, j, m, n, p, f=0;
cout<<"\nEnter the size of the Array(rows, column):\n";
cin>>m>>n;
cout<<"\nEnter the elements of the Array:\n";
for(i=0;i < m;i++)
{
for(j=0;j < n;j++)
cin>>a[i][j];
}
cout<<"\nEnter the number to search: ";
cin>>p;
for(i=0;i < m;i++)
{
for(j=0;j < n;j++)
{
if(p==a[i][j])
{
cout<<"\nNumber is found at "<<i+1<<" row and "<<j+1<<" column.";
f=1;
}
}
}
if(f==0)
cout<<"Number not found.";
}
Count of integers
{
int a[180][180], i, j, m, n, cp=0, cn=0, c0=0;
cout<<"\nEnter the size of the Array(rows, column):\n";
cin>>m>>n;
cout<<"\nEnter the elements of the Array:\n";
for(i=0;i < m;i++)
{
for(j=0;j < n;j++)
cin>>a[i][j];
}
for(i=0;i < m;i++)
{
for(j=0;j < n;j++)
{
if(a[i][j]>0)
cp++;
else if(a[i][j]<0)
cn++;
else
c0++;
}
}
cout<<"\nNo. positive integers="<<cp<<"\nNo. of negative integers="<<cn<<"\nNo. of zeroes="<<c0;
}
Maximum and Minimum
{
int a[180][180], i, j, m, n, max, min;
cout<<"\nEnter the size of the Array(rows, column):\n";
cin>>m>>n;
cout<<"\nEnter the elements of the Array:\n";
for(i=0;i < m;i++)
{
for(j=0;j < n;j++)
cin>>a[i][j];
}
max=a[i][j]; min=a[i][j];
for(i=0;i < m;i++)
{
for(j=0;j < n;j++)
{
if(max<a[i][j])
max=a[i][j];
if(min>a[i][j])
min=a[i][j];
}
}
cout<<"\nMaximum of the elements is: "<<max<<"\nMinimum of the elements is: "<<min;
}
No comments:
Post a Comment