Monday 6 July 2020

Record input and search program structure | C Language

Q : Write a ‘C’ program to read following details of 50 students.
      Student Name, Student Roll No, Class 
 Display total number of students studying in class “BCA”.

Answer : 



#include<stdio.h>
#include<conio.h>
#include "mylib.h"
/*============================
     Girfa Student Help
     Structure entry & search count
==============================*/
struct data
{
     int roll;
     char name[20];
     char cls[50];
};

void main()
{
     struct data stu[50];
     int i,count,j;
     char search[50];
     clrscr();
     printf("How many record you want to enter>> ");
     scanf("%d",&i);
     if(i>50)
           printf("Sorry only 50 records can be entered");
     else
     {
           for(j=0;j<i;j++)
           {
                printf("Enter roll>> ");
                scanf("%d",&stu[j].roll);
                fflush(stdin);
                printf("Enter name>> ");
                gets(stu[j].name);
                fflush(stdin);
                printf("Enter course>> ");
                gets(stu[j].cls);
           }
           printf("Enter course for search>> ");
           gets(search);
           count=0;
           for(j=0;j<i;j++)
           {
                if(strcmp(stu[j].cls,search)==0)
                     count++;
           }
           printf("\nCourse %s count is %d",search,count);
     }
     getch();
}


No comments:

Post a Comment