//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;
}
#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