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

Clay is an example of

A) Aquiclude B) Glossy
C) Utilitarian D) None of the above
 
Answer & Explanation Answer: A) Aquiclude

Explanation:

Clay is an example of Aquiclude.

Report Error

View Answer Report Error Discuss

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

0 4454
Q:

Which is not a task of a configuration management?

A) Reporting B) Version control
C) Quality control D) Change management
 
Answer & Explanation Answer: C) Quality control

Explanation:
Report Error

View Answer Report Error Discuss

6 4453
Q:

World Soil Day is celebrated on ?

A) July 26 B) June 30
C) August 9 D) December 5
 
Answer & Explanation Answer: D) December 5

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Important Days and Years
Exam Prep: AIEEE , Bank Exams , CAT
Job Role: Bank Clerk , Bank PO

15 4450
Q:

Niligiri Tahr is the state animal of which of the following states ?

A) Tamil Nadu B) Karnataka
C) Maharashtra D) Kerala
 
Answer & Explanation Answer: A) Tamil Nadu

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Animals and Birds
Exam Prep: Bank Exams , CAT
Job Role: Bank Clerk

20 4448
Q:

Which planet has the lowest density?

A) Earth B) Jupiter
C) Saturn D) Neptune
 
Answer & Explanation Answer: C) Saturn

Explanation:

Saturn, the solar system's second largest planet that takes the prize for least dense. It's less dense than water, which has led many people to postulate that it would float.

However, even if it somehow found its way to a body of water large and deep enough to contain it, Saturn would break apart and its rocky core would sink.

Report Error

View Answer Report Error Discuss

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

1 4448
Q:

Which feature do Prokaryotic and Eukaryotic cells share

A) Nucleus B) DNA
C) Nuclear membrane D) Membrane bound Organelles
 
Answer & Explanation Answer: B) DNA

Explanation:

Prokaryotic and Eukaryotic cells do share a feature of DNA.

Both prokaryotic and eukaryotic cells have structures in common.

All cells have a plasma membrane, ribosomes, cytoplasm, and DNA.

Prokaryotic cells are primitive cells which have no true nucleus and membrane bound organelles, while Eukaryotic cells are cells that have true nucleus, membrane bound organelles and well defined structures and layouts.

Report Error

View Answer Report Error Discuss

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

5 4447
Q:

Coir, Copra, Coconut , Cashew are mainly exported from

A) Mumbai B) Cochin
C) Tuticorin D) Chennai
 
Answer & Explanation Answer: B) Cochin

Explanation:

Because Kerala is the major producer of these products.

Report Error

View Answer Report Error Discuss

Filed Under: Indian Geography

9 4447