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 4458
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 4457
Q:

Give examples for 8/16/32 bit Microprocessor?

Answer

8-bit processor - 8085/Z80/6800;


16-bit processor - 8086/68000/Z8000;


32-bit processor - 80386/80486

Report Error

View answer Workspace Report Error Discuss

Subject: Hardware

2 4457
Q:

In Which Indian state is the world's highest cricket ground located ?

A) Himachal Pradesh B) Uttarakhand
C) West Bengal D) Jammu Kashmir
 
Answer & Explanation Answer: A) Himachal Pradesh

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Books and Authors

11 4454
Q:

How many Nephrons are in each kidney?

A) 10,000 B) 1,00,000
C) 1,000,000 D) 1000
 
Answer & Explanation Answer: C) 1,000,000

Explanation:

There are about 1,000,000 nephrons in each human kidney.

Nephron, functional unit of the kidney, the structure that actually produces urine in the process of removing waste and excess substances from the blood.

Report Error

View Answer Report Error Discuss

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

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

The fastest moving land snake in the world is the

Answer

Black Mamba

Report Error

View answer Workspace Report Error Discuss

25 4452
Q:

When is the ' World AIDS Day ' observed all over the world

A) 1st october B) 12th December
C) 1st December D) 13th November
 
Answer & Explanation Answer: C) 1st December

Explanation:
Report Error

View Answer Report Error Discuss

5 4447