-
Notifications
You must be signed in to change notification settings - Fork 16
/
14.c
58 lines (48 loc) · 1.39 KB
/
14.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <string.h>
#define MAX_STUDENTS 100
struct Student
{
char name[50];
int rollNumber;
};
int main()
{
struct Student directory[MAX_STUDENTS];
int numStudents;
int i;
printf("Enter the number of students: ");
scanf("%d", &numStudents);
for (i = 0; i < numStudents; i++)
{
printf("Enter the name of student %d: ", i + 1);
scanf("%s", directory[i].name);
printf("Enter the roll number of student %d: ", i + 1);
scanf("%d", &directory[i].rollNumber);
}
char searchName[50];
int searchRollNumber;
printf("Enter the name to search for roll number: ");
scanf("%s", searchName);
for (i = 0; i < numStudents; i++)
{
if (strcmp(directory[i].name, searchName) == 0)
{
searchRollNumber = directory[i].rollNumber;
printf("Roll number for %s is %d\n", searchName, searchRollNumber);
break;
}
}
printf("Enter the roll number to search for name: ");
scanf("%d", &searchRollNumber);
for (i = 0; i < numStudents; i++)
{
if (directory[i].rollNumber == searchRollNumber)
{
strcpy(searchName, directory[i].name);
printf("Name for roll number %d is %s\n", searchRollNumber, searchName);
break;
}
}
return 0;
}