-
Notifications
You must be signed in to change notification settings - Fork 16
/
14.c
42 lines (37 loc) · 942 Bytes
/
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct student
{
int roll_no;
char name[50];
};
int main()
{
struct student students[100];
int n;
printf("Enter the number of students: ");
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
printf("Enter the roll number of student %d: ", i+1);
scanf("%d", &students[i].roll_no);
printf("Enter the name of student %d: ", i+1);
scanf("%s", students[i].name);
}
printf("\n\n");
printf("Type student name or roll number to search: \n");
char search[50];
scanf("%s", search);
int found = 0;
for (int i = 0; i < n; i++)
{
if (students[i].roll_no == atoi(search) || strcmp(students[i].name, search) == 0)
{
printf("Roll No: %d\n", students[i].roll_no);
printf("Name: %s\n", students[i].name);
found = 1;
break;
}
}
}