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

Answer the Following Puzzle.

Number_Puzzles_Typical_Aptitude_Questions_and_Answers1585548407.png image

A) 1111 B) 4311
C) 1143 D) 4343
 
Answer & Explanation Answer: C) 1143

Explanation:

Starting with the top 3 digit number, the first digit increases by 2 as you descend,from 1 to 11. The middle digit decreases by 1 each time,and the right hand digit alternates between 5 and 3

Report Error

View Answer Report Error Discuss

Filed Under: Number Puzzles
Exam Prep: CAT , Bank Exams

13 4093
Q:

Write a c program to find out sum of diagonal element of a matrix.

Answer

#include<stdio.h>

int main(){

  int a[10][10],i,j,sum=0,m,n;

  printf("\nEnter the row and column of matrix: ");
  scanf("%d %d",&m,&n);

  printf("\nEnter the elements of matrix: ");
  for(i=0;i<m;i++)
      for(j=0;j<n;j++)
           scanf("%d",&a[i][j]);
  printf("\nThe matrix is\n");

  for(i=0;i<m;i++){
      printf("\n");
      for(j=0;j<m;j++){
      printf("%d\t",a[i][j]);
      }
 }
 for(i=0;i<m;i++){
     for(j=0;j<n;j++){
          if(i==j)
              sum=sum+a[i][j];
     }
 }
 printf("\n\nSum of the diagonal elements of a matrix is: %d",sum);

 return 0;
}

Sample output:

Enter the row and column of matrix: 3 3
Enter the elements of matrix:
2
3
5
6
7
9
2
6
7
The matrix is
2       3       5
6       7       9
2       6       7
Sum of the diagonal elements of a matrix is: 16

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

1 4091
Q:

What is the official language of African Export and import Bank

A) Egypt B) Senegal
C) Dauber D) None of these
 
Answer & Explanation Answer: A) Egypt

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: World Organisations

4 4091
Q:

Streptomycin was invented by

A) Fleming B) Marie Curie
C) Walksman D) None of these
 
Answer & Explanation Answer: C) Walksman

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Inventions

1 4091
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 4091
Q:

If there are 17 randomly placed dots on a circle,how many lines can you form using any 2 dots?

A) 126 B) 130
C) 136 D) 120
 
Answer & Explanation Answer: C) 136

Explanation:

17C2 = 136 (combination)

Report Error

View Answer Report Error Discuss

0 4090
Q:

The famous song ‘Saare Jaha se Achha’ is composed by ___________

A) Ravindra Nath Tagore B) Bankim Chandra Chattopadhya
C) Mohammad Iqbal D) one of the above
 
Answer & Explanation Answer: C) Mohammad Iqbal

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Indian Culture

53 4090