Questions

Q:

How would you use qsort() function to sort an array of structures?

Answer

#include "string.h"


#include "stdlib.h"


struct stud


{


       int rollno;


       int marks;


       char name[30];


};


int sort_m (struct stud *, struct stud *);


int sort_name (struct stud *, struct stud *);


int sort_marks (struct stud *, struct stud *);


 


main()


{


static struct stud ss[] = {


                                            { 15, 96, "Akshay" },


                                            { 2, 97, "Madhuri" },


                                            { 8, 85, "Aishvarya" },


                                            { 10, 80, "Sushmita" }


                                   };


int x,w;


clrscr();


w = sizeof (struct stud);


 


printf ('\nIn order of roll numbers:");


qsort (ss, 4, w, sort_rn);


for(x=0; x<4;x++)


     printf ("\n%d%s%d", ss[x].rollno, ss[x].name,ss[x].marks);


 


printf("\n\nIn order of names:");


qsort(ss, 4, sort_name);


 


for (x=0; x<4;x++)


      printf("\n%d%s%d",ss[x].rollno, ss[x].name,ss[x].marks);


printf("\n\nIn order of marks:");


qsort(ss,4,w,sort_marks);


 


for (x=0;x<4;x++)


      printf ("\n%d%s%d",ss[x].rollno,ss[x].name,ss[x].marks);


}


int sort_rn (struct stud *t1, struct stud *t2)


{


     return (t1->rollno-t2->rollno);


}


 


int sort_name (struct stud *t1, struct stud *t2)


{


     return (strcmp(t1->name,t2->name));


}


int sort_marks (struct stud *t1, struct stud *t2)


{


     return (t2->marks-t1->marks);


}


 


 


 

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 4114
Q:

What has a mouth but never smiles?

Answer

A bottle has a mouth from which we used to drink water or any juice. But it cannot smile.

Report Error

View answer Workspace Report Error Discuss

Subject: Word Puzzles Exam Prep: TOEFL , GRE , GATE , CAT , Bank Exams , AIEEE
Job Role: Bank PO , Bank Clerk , Analyst

13 4113
Q:

People buy me to eat but never eat me?

Answer

I ama PLATE.


People used me to eat their food but cannot eat me.

Report Error

View answer Workspace Report Error Discuss

Subject: Logic Puzzles Exam Prep: GRE , CAT , Bank Exams

91 4113
Q:

Gear Lapping is an operation

A) for gear reconditioning B) prior to heat treatment
C) after heat treatment D) None of the above
 
Answer & Explanation Answer: C) after heat treatment

Explanation:

Gear Lapping is an operation after heat treatment. Gear lapping is the process of imparting a very fine finish and high degree of accuracy to gear teeth, by using a lapping tool and applying a fine-grained abrasive between a work material and a closely fitting surface, called a lapping plate.

Gear_Lapping_is_an_operation1554186430.jpg image

Report Error

View Answer Report Error Discuss

Filed Under: Physics
Exam Prep: AIEEE , Bank Exams , CAT
Job Role: Analyst , Bank Clerk , Bank PO

1 4112
Q:

'Roaring Forties' are 

A) waterfalls in canada B) cyclonic winds
C) the turbulent years in world History from 1940 to 1944 D) westerly winds blowing through out the year over the oceans of the Southern Hemisphere between 40 degrees and 60 degrees south
 
Answer & Explanation Answer: D) westerly winds blowing through out the year over the oceans of the Southern Hemisphere between 40 degrees and 60 degrees south

Explanation:

The absence of a landmass within these latitudes in the southern hemisphere eliminate friction and lends force to these winds and hence derives the name

Report Error

View Answer Report Error Discuss

Filed Under: World Geography

0 4111
Q:

Spices detoriate after prolonged boiling

A) The essential oils in the spices easily evaporate B) Spices are put in the pickels to add to the flavour
C) Both A and B D) None
 
Answer & Explanation Answer: A) The essential oils in the spices easily evaporate

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Biology

5 4111
Q:

Famous play ' Macbeth ' is written by

A) Leo Tolstoy B) William Shakespeare
C) john Milton D) Charles Dickens
 
Answer & Explanation Answer: B) William Shakespeare

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Books and Authors

6 4110
Q:

An Oracle System Change Number (SCN):

A) is a value that is incremented whenever a dirty read occurs. B) is incremented whenever a deadlock occurs.
C) is a value that keeps track of explicit locks. D) is a value that is incremented whenever database changes are made.
 
Answer & Explanation Answer: D) is a value that is incremented whenever database changes are made.

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Database

0 4109