#include <stdio.h>
struct movie
{
char name [50];
int len;
double rate;
}list [100],temp;
void rate (int n);
void sort (int n);
void main ()
{
int i,j,n;
printf("Number of Movies: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
getchar();
printf("Movie name: ");
gets(list[i].name);
printf("Movie length: ");
scanf("%d",&list[i].len);
printf("Movie Rate: ");
scanf("%lf",&list[i].rate);
printf("\n\n");
}
rate (n);
}
void rate (int n)
{
int i;
double max=list[0].rate;
for(i=0;i<n;i++)
{
if(list[i].rate>max)
max=list[i].rate;
}
for(i=0;i<n;i++)
{
if(list[i].rate==max)
{
printf("\nTop Rated Movie is : %s\n",list[i].name);
break;
}
}
sort(n);
}
void sort (int n)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(list[i].len>list[j].len)
{
temp=list[i];
list[i]=list[j];
list[j]=temp;
}
}
}
printf("\nMovie list by shortest length\n");
printf("\nNo.\tMovie Name\n");
for(i=0;i<n;i++)
{
printf("%d\t%s\n",i+1,list[i].name);
}
}
No comments:
Post a Comment