Algorithm
1. Declare Value of Char - 10 Names - Size of Names - 3
2. Run For Loop
3. Taking 10 Names
4. Using For Loop again
5. Taking which name to be searched
6. If name found it will ask again which name to be searched
Code
#include<stdio.h>
#include<string.h>
int main(void)
{ char names[10][3], sname[20];
int i, flag;
printf("Enter ten names \n");
for(i=0; i<10; i++)
scanf("%s", names[i]);
for(i=0; i<10; i++){
printf("Enter name to be searched \n");
scanf("%s", sname);
/*Searching for sname in names begins*/
flag=0;
for(i=0; i<10; i++)
if(strcmp(names[i], sname) == 0)
{
flag = 1;
break;
}
/*Searching for sname in names ends*/
if(flag)
printf("%s is found \n", sname);
else
printf("%s is not found \n", sname);
}
return 0;
}
Output
PS C:\Users\anmol> cd "c:\Users\anmol\OneDrive\Desktop\Collage\Sem-1\C Projects\" ; if ($?) { gcc tempCodeRunnerFile.c -o tempCodeRunnerFile } ; if ($?) { .\tempCodeRunnerFile }
Enter ten names
A
B
C
D
E
F
C
H
I
J
Enter name to be searched
D
D is found