Posts

Showing posts with the label Assignment 7

Assignment 7 Question 2

#include <stdio.h> #include <stdlib.h> struct node {     int data;     struct node *next; }; typedef struct node NODE; int main() {     NODE *head=NULL;     NODE *tail=NULL;     int a,n;     scanf("%d",&a);     while(a!=-1)     {         NODE *s;         s=(NODE *)malloc(sizeof(NODE));         s->data=a;         s->next=NULL;         if(head==NULL)         {              head=s;              tail=s;         }         else         {             tail->next=s;             tail=s;         }         scanf("%...

Assignment 7 Question 1

#include <stdio.h> struct details{ char name[128]; int p,c,m; }; int main() { int i,j,n; scanf("%d", &n); struct details a[n]; for(i=0;i<n;i++) { scanf("%s %d %d %d", a[i].name,&a[i].p,&a[i].c,&a[i].m); } struct details temp; for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(j+1==n){ break; } if(a[j].p>a[j+1].p) { temp=a[j+1]; a[j+1]=a[j]; a[j]=temp; }else if(a[j].p==a[j+1].p) { if(a[j].c>a[j+1].c) { temp=a[j+1]; a[j+1]=a[j]; a[j]=temp; }else if(a[j].c==a[j+1].c) { if(a[j].m>a[j+1].m) { temp=a[j+1]; a[j+1]=a[j]; a[j]=temp; } } } } } for(i=0;i<n;i++) { printf("%s-%d-%d-%d\n", a[i].name,a[i].p,a[i].c,a[i].m); } return 0; }