Posts

Java Question Data structure 07

Image
Consider the following array of sorted integers.  10,15,25,30,33,34,46,55,78,84,96,99  Using binary search algorithm, search for 23. //Q7.java public class Q7 {      public static void binarySearch ( int [] arr , int num )     {                   //initialize low mid and high          int low = 0 ;          int high = arr . length - 1 ;          int mid = 0 ;                   //binary search logic          while (low <= high)         {             mid = (low + high) / 2 ;      ...

Java Question Data structure 04

Image
Given a two-dimensional array, write a program to print it out in spiral order,  Ex: 1 2   3   4        5 6   7   8         9 10 11 12         13 14 15 16  Output: 1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10     //Q4.java public class Q4 { public static void main ( String args []) { int [][] mat = { { 1 , 2 , 3 , 4 }, { 5 , 6 , 7 , 8 }, { 9 , 10 , 11 , 12 }, { 13 , 14 , 15 , 16 } }; int top = 0 , bottom = mat . length - 1 ; int left = 0 , right = mat[ 0 ]. length - 1 ; while ( true ) { if (left > right) { break ; } for ( int i = left ; i <= right ; i ++ ) { System . out . print (mat[top][i] ...

Download source files

Structure of C++

Image
Structure of C++   Line 01 : //my first program in C++ Two slash signs indicate that the rest of the line is a comment inserted by the programmer but which has no effect on the behavior of the program. programmers use them to include short explanations or observations concerning the code or program. in this case, it is a brief introductory description of the program Line 02 : #include<iostream> Lines beginning   with a hash sign(#) are directives read interpreted by what is know as the preprocessor. They are special lines interpreted before the compilation of the program itself begins. In this case the directive #include<iostream> instructs the preprocessor to include a section of standard C++ code know as header iostream that allows to perform standard input and output operations, such as writing the output of this program (HELLO WORLD) to the screen. Line 03 : using namespace std; All the elements of the stranded C++ library are declared with in what is ...

Sample Qustion 12

Image
Write a C++ program to multiply 2 arrays of size 3*4 and 4*2.RTead values for 2 arrays from user      #include <iostream>     using namespace std;     int main()     {         int a[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, i, j, k;         cout << "Enter rows and columns for first matrix: ";         cin >> r1 >> c1;         cout << "Enter rows and columns for second matrix: ";         cin >> r2 >> c2;         while (c1!=r2)         {             cout << "Error! column of first matrix not equal to row of second.";        ...

Sample Qustion 11

Image
Write a C++ program to add given 2 arrays.      int arr1[3][2]={{12,45},{21,89},{20,9}}      int arr2[3][2]={{20,15},{30,10},{4,7}}      #include <iostream>     using namespace std;     int main()     {         int a[3][2]={{14,15},{21,89},{20,9}};         int b[3][2]={{20,15},{30,10},{4,7}};         int sum [3][2];         int r =3;         int c = 2;         for(int i = 0; i < r; ++i)             for(int j = 0; j < c; ++j)                 {              ...

Sample Qustion 10

Image
Write a C++ program to display              a. Smallest value in each column              b. Smallest value in each row              c. Largest value in each column              d. Largest value in each row              e. Overall smallest value and largest value              f. Column name of the overall largest                             value                         ...

Sample Qustion 9

Image
Write a C++ program to display the smallest and greatest of given values. It also displays the value that occurs the most.              2,5,12,78,21,56,90,32,12,90,90,12  #include<iostream> using namespace std; int main() {     int arr[15] = {2,5,12,78,21,56,90,32,12,90,90,12};     int maxnum = arr[0];     int minnum = arr[0];   for (int i = 0; i < 12; i++)     {       if (arr[i] > maxnum)         {           maxnum = arr[i];         }       else if (arr[i] < minnum)         {           minnum = arr[i];         }     }   ...