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

Solve this Math puzzle?

math_number_puzzle1538999808.jpg image

A) 96 B) 88
C) 40 D) 19
 
Answer & Explanation Answer: A) 96

Explanation:

The given math puzzle follows a logic that,

1 + 4 = 5 => 1 x 4 + 1 = 5

2 + 5 = 12 => 2 x 5 + 2 = 12

3 + 6 = 21 => 3 x 6 + 3 = 21

 

Similarly,

8 + 11 = > 8 x 11 + 8 = 96.

Report Error

View Answer Report Error Discuss

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

9 4407
Q:

I act like a cat I look like a cat Yet I am not a cat. What am I?

Answer

A Kitten.

Report Error

View answer Workspace Report Error Discuss

Subject: Word Puzzles Exam Prep: Bank Exams

12 4407
Q:

How many Teaspoons in a Tablespoon?

A) 4 B) 5
C) 2 D) 3
 
Answer & Explanation Answer: D) 3

Explanation:

Tablespoon > Teaspoon

In US & UK, 1 Tablespoon = 3 Teaspoons.

Report Error

View Answer Report Error Discuss

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

Math Logic Challenge

18582095_1309614185812349_1823149961450714717_n1499156071.jpg image

A) 23 B) 26
C) 13 D) 29
 
Answer & Explanation Answer: B) 26

Explanation:

Let the integer be x. Then,

 x2-20x = 156

 

(x + 6)(x - 26) = 0

 

x = 26

 

The integer is 26.

Report Error

View Answer Report Error Discuss

Filed Under: Math Puzzles
Exam Prep: GATE , CAT , Bank Exams , AIEEE
Job Role: Bank PO , Bank Clerk

12 4402
Q:

Which newspaper has acquired 67 per cent stake in Kolkata-based daily The Asian Age?

A) Hindustan Times B) Times of India
C) Deccan Chronicle D) The Hindu
 
Answer & Explanation Answer: C) Deccan Chronicle

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Business Awareness

11 4401