All Programs are Written and Compiled in Dev C++. So, it may generate some error in case of other compilers and may need some modifications in program. Download Dev C++

Wednesday, 26 February 2014

Searching in a Tabular Array

//Searching in a Tabular Array
#include<iostream.h>
#include<conio.h>
int main()
{
      int a[10];
      float b[10];
      char c[10][10];
      int m,i,roll,found=0,loc;
      cout<<"Enter no of elements in array";
      cin>>m;
      cout<<"Enter Roll no, Marks & Name"<<endl;
      for(i=0;i<m;i++)
      {
     cin>>a[i]>>b[i];
     cin>>c[i];
      }
      cout<<"Enter Roll No to search";
      cin>>roll;
      for(i=1;i<=m;i++)
      {
                       if(roll==a[i])
                       {
                                    found=1;
                                    loc=i;
                       }
      }
//printing Table    
      cout<<"Roll No"<<"\t"<<"Marks"<<"\t"<<"Name"<<endl;
      for(i=0;i<m;i++)
      {
cout<<a[i]<<"\t"<<b[i]<<"\t";
cout<<c[i]<<endl;
      }
     
 if(found==1)
             cout<<"found at location "<<loc;
      else
          cout<<"not found";
getch();
return 0;
}

No comments:

Post a Comment