Friday, 22 June 2012

write a c program to accept n names from user store these name in 2_D array. accept the name from the user and search whether the name is present in array or not


/* write a c program to accept n names from user store these name in 2_D
array. accept the name from the user and search whether the name is present
in array or not */

#include<stdio.h>
#include<conio.h>
void main()
{
char name[5][10],temp[20],i,j,data[30],d,p;
int n;
clrscr();
printf("\nhow many number :");
scanf("%d",&n);
printf("\nenter the name :");
for(i=0;i<n;i++)
{
flushall();
gets(name[i]);
}
printf("\nenter the names which you want to search :");
scanf("%s",&data);
for(i=0;i<n;i++)
{
flushall();
d=strcmp(data,name[i]);
if(d==0)
{
p=0;
break;
}
}
if(p==0)
printf("it is exist in array");
else
printf("it is not exist in array");
getch();
}
/*
how many number :4                                                            
                                                                               
enter the name :peer                                                          
san                                                                            
fear                                                                          
rahul                                                                          
                                                                               
enter the names which you want to search :fear                                
it is exist in array                                                          
                                                                               
   */

No comments: