Write a C program to read name, usn and marks of N students using structure. Also search a given student name to display marks.

 Write a C program to read name, usn and marks of N students using structure. Also search a given student name to display marks.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student
{
int usn, marks;
char name[30];
};
void main()
{
int i, n;
char sname[30];
struct student s[100];

printf(“Enter the number of students \n”);
scanf (“%d” , &n);
for (i=0; i<n; i++)
{

printf(“Enter the USN:”);
scanf (“%d”, &s[i].usn);
printf (“Enter the name of student:”);
scanf (“%s”, s[i]. name);
printf (“Enter the marks:”);
scanf (“%d”, &s[i]. marks);

}
printf (“Enter the name of student to be searched for marks\n”);
scanf (“%s”, sname);
for(i=0; i<n; i++)
{

if (strcmp(sname, s[i].name) = = 0)

{

printf(“%s is scored %d marks”, sname, s[i].marks);
exit(0);

}

}
printf (“Student is not found”);

}

Comments