Computer Concept & Programming In C - Unit IV - 7

Q.12 Write a program in C that compares two given dates. To store a date,use a structure that contains three members namely day, month and year. If the dates are equal then display message as "equal" otherwise "unequal".   (AKTU. 2008 - 09)
Related Questions -
Q. Write a program to show the usage of structure in C.      (AKTU. 2009-10)
Ans.
#include<stdio.h>
#include<conio.h>

/* Declaring the date structure */

struct date{
int day;
int month;
int year;
};

void main()
{
  /* Declaring structured variable of date */

 struct date d1, d2;
 int flag = 0;
 clrscr();

 /* Taking input for the first date*/

 printf("\n This for first date");
 printf("\nDay = ");
 scanf("%d",&d1.day);
 printf("\nMonth = ");
 scanf("%d",&d1.month);
 printf("\nYear = ");
 scanf("%d",&d1.year);
 printf("\n");

 /* Taking input for the second date */
 printf("\n This for second date");
 printf("\nDay = ");
 scanf("%d",&d2.day);
 printf("\nMonth = ");
 scanf("%d",&d2.month);
 printf("\nYear = ");
 scanf("%d",&d2.year);
 printf("\n");

 /* Checking the equality of the dates */

 if(d1.day == d2.day)
   if(d1.month == d2.month)
     if(d1.year == d2.year)
       {
printf("\n Dates are EQUAL");
flag = 1;
       }
 if(flag == 0)
   printf("\n Dates are UNEQUAL");

printf("\nPress any key to exit.");
getch();
}

Q.13 Write a program in C that accpets roll number and name of student’s of a class size of one hundred students along with the marks obtained by them in physics, Chemistry and Mathematics. Print roll number and the name of top ten students in the order of merit. The merit is based on the sum of the marks obtained in the three subjects.     (AKTU. 2009-10)
Ans.
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define size 100
void main()
{
 int i, j;
 struct student
{
 int roll_no;
 char name[30];
 int physics;
 int chemistry;
 int maths;
 int total ;
} temp, stu[size];
 clrscr();

 //Input

 for( i = 0; i < size; i++)
    {
      printf("\nEnter the Information of student %d", (i + 1));

      printf("\nName :");
      scanf("%s",&stu[i].name);

      printf("\nRoll_No.\n");
      scanf("%d", &stu[i].roll_no);

      printf("\nMarks in Physics\n");
      scanf("%d", &stu[i].physics);

      printf("\nMarks in Chemistry\n");
      scanf("%d", &stu[i].chemistry);

      printf("\nMarks in Maths\n");
      scanf("%d", &stu[i].maths);

      stu[i].total = stu[i].physics + stu[i].chemistry + stu[i].maths ;
    }

  //Sorting array using Bubble Sort
 for( i = 0; i < size; i++)
   {
    for( j = 0; j < size; j++)
       {
 if(stu[j].total < stu[j + 1].total)
   {

      temp = stu[i];
      stu[i] = stu[j + 1];
      stu[j + 1 ] = temp;

   }
}
   }

   //Output
   printf("\nMerit List of top 10 students:\n");
   for( i = 0; i < 10; i++)
    {
      printf("\nRank %d : ", ( i + 1 ));

      printf("\nName :");
      printf("%s",stu[i].name);

      printf("\nRoll_No.");
      printf("%d", stu[i].roll_no);

      printf("\nTotal :");
      printf("%d", stu[i].total);
    }
   getch();
}