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 3900
Q:

A gas is found to have the formula . Its vapour density is 70.The value of n must be

A) 5 B) 4
C) 9 D) 6
 
Answer & Explanation Answer: A) 5

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Chemistry

3 3900
Q:

The vitamin required for coagulation of blood

A) B6 B) c
C) k D) b
 
Answer & Explanation Answer: C) k

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Biology

8 3900
Q:

The Supreme Court has reconstituted the special Investigation Team(SIT) to expedite probe into Black Money Cases and directed the government to issue the necessary notification. Who of the following is the chairman of this team?

A) Arijit Pasayat B) M.B.Shah
C) R.M.Lodha D) Vinod Rai
 
Answer & Explanation Answer: B) M.B.Shah

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: General Awareness

3 3899
Q:

Who holds the post of Deputy Chairman of the Planning Commission?

 

A) Prime Minister B) Planning Minister
C) an official who holds the rank of a Cabinet Minister D) an economist of repute
 
Answer & Explanation Answer: C) an official who holds the rank of a Cabinet Minister

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Indian Politics
Exam Prep: Bank Exams

0 3897
Q:

[(24)2+(27)2]÷? = 9.0625

A) 121 B) 144
C) 169 D) 81
 
Answer & Explanation Answer: B) 144

Explanation:
Report Error

View Answer Report Error Discuss

4 3896
Q:

Which atom has the largest radius?

A) Neon B) Francium
C) Helium D) Cesium
 
Answer & Explanation Answer: B) Francium

Explanation:

which_atom_has_the_largest_radius1537434800.gif image

In the periodic table, the atomic radius increases from top to bottom in the groups and it increases from right to left in the periods.

 

Francium is the atom with largest atomic radius. Helium is the atom with smallest radius.

Report Error

View Answer Report Error Discuss

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

3 3895
Q:

MS Kim Campbell is the first Prime Minister of

A) Congo B) Canada
C) Portugal D) Phillippines
 
Answer & Explanation Answer: B) Canada

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Famous Personalities

0 3894