Showing posts with label matrix. Show all posts
Showing posts with label matrix. Show all posts

Wednesday, 1 February 2012

Program To Print Left Digonal of Matrix In C++


#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
cout<<"\n Enter Rows=";
cin>>m;
cout<<"Enter COlumns=";
cin>>n;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<"ENter Number=";
}
}
cout<<"\n ===============First Matrix IS==========================\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
{
cout<<"\t"<<a[i][j];
}
else
{
cout<<"\t";
}
}
cout<<"\n";
}


getch();
}

Saturday, 14 January 2012

Program of Linear Search In C++

#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int a[10],n,i,item,f=0,pos=0,count=0;
cout<<"Enter Number of Elements=";
cin>>n;
for(i=0;i<n;i++)
{
 cout<<"Enter NUmber=";
 cin>>a[i];
}
cout<<"\n=============== Array is==================\n";
for(i=0;i<n;i++)
{
 cout<<"\n"<<a[i];
}

cout<<"\n Enter Number Of item to be Search=";
cin>>item;
for(i=0;i<n;i++)
{
if(a[i]==item)
{
f=1;
pos=i+1;
cout<<"\n Item FOund at ==> "<<pos;
count++;
}

}
if(f==1)
{
cout<<"\n Item Found "<<count<<"  Times " ;
}
else
{
cout<<"Item Not Found";
}

getch();
}

-----------------------------------------------------------------------------------


In computer science, linear search or sequential search is a method for finding a particular value in a list, that consists of checking every one of its elements, one at a time and in sequence, until the desired one is found.

Linear search is the simplest search algorithm; it is a special case of brute search. Its worst case cost is proportional to the number of elements in the list; and so is its excepted cost, if all list elements are equally likely to be searched for. Therefore, if the list has more than a few elements, other methods  will be faster, but they also impose additional requirements




VIEW SOURCE:-  http://en.wikipedia.org/wiki/Linear_search