EQuestionAnswers.com Notes, Syllabus, Questions, Ideas,
Books, Reference materials on Electronics
#Login #Sign up #Forum #Feedback
 

Write a program to show student database using data structure.

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
  clrscr();
  int i,j;
  float tf=0;
  int ti=0;
10    char t[100];
11    struct student
12    {
13      char name[100];
14      char dept[100];
15      int rollno;
16      float marks;
17    };
18    struct student s[5];
19    printf("\nEnter the name, dept, roll number and marks of five students:\n");
20    for(i=0;i<5;i++)
21    {
22      scanf("%s %s %d %f",&s[i].name,&s[i].dept,&s[i].rollno,&s[i].marks);
23    }
24    for(i=0;i<5;i++)
25    {
26      for(j=i;j<5;j++)
27      {
28             if(s[i].marks>s[j].marks)
29             {
30          tf=s[i].marks;
31          s[i].marks=s[j].marks;
32          s[j].marks=tf;
33          ti=s[i].rollno;
34          s[i].rollno=s[j].rollno;
35          s[j].rollno=ti;
36          strcpy(t,s[i].dept);
37          strcpy(s[i].dept,s[j].dept);
38          strcpy(s[j].dept,t);
39          strcpy(t,s[i].name);
40          strcpy(s[i].name,s[j].name);
41          strcpy(s[j].name,t);
42             }
43      }
44    }
45    printf("\nThe students are:");
46    for(i=0;i<5;i++)
47    {
48      printf("\n%s %s %d %f",s[i].name,s[i].dept,s[i].rollno,s[i].marks);
49    }
50 
51    getch();
52  }

Find More from our code collection
Armstrong number, binary number to a decimal number, bubble sort, decimal number to binary number, factorial of the given number factors, fibonacci numbers, HCF and LCM, matrix, mergesort, salary of the employee. palindrome, quadratic equation, star patterns, series etc. and much more...
#Return to Example Source Code