Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


There are two sorted arrays
a1 and a2 of size n1 and size n2 respectively.
array a1 is full
array a2 has exactly n1(size of array a1) empty space.
example
a1[]=1234
a2[]=56789_ _ _ _
Write a function to merge these two arrays to form a sorted
array without any extra memory use.

i want a solution in c/c++ language

Answers were Sorted based on User's Feedback



There are two sorted arrays a1 and a2 of size n1 and size n2 respectively. array a1 is full array..

Answer / ajay

class A
{
public static void main(String args[])
{
int[] a1={1,2,3,4};
int[] a2=new int[9];

a2[0]=5; a2[1]=6; a2[2]=7; a2[3]=8; a2[4]=9;

for(int i=8;i>=4;i--)
a2[i]=a2[i-4];

for(int i=0;i<=3;i++)
a2[i]=a1[i];


for(int i=0;i<=8;i++)
System.out.println(a2[i]);

}
}

Is This Answer Correct ?    2 Yes 1 No

There are two sorted arrays a1 and a2 of size n1 and size n2 respectively. array a1 is full array..

Answer / surjeet gangwar

import java.util.*;
class arrtest
{
int[][] a=new int[3][3];
int[][] b={{1,1,1},{1,1,1},{1,1,1}};

public arrtest()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the matrix:\n");
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
a[i][j]=sc.nextInt();
}

void oper()
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
if(a[i][j]==0)
for(int k=0;k<3;k++)
{
b[i][k]=0;
b[k][j]=0;
}
}

void print()
{
System.out.println(" the matrix:\n");
for(int i=0;i<3;i++)
{ for(int j=0;j<3;j++)
System.out.print("\t"+b[i][j]);

System.out.println("\n");
}
}
}
class arrdemo
{
public static void main(String a[])
{
arrtest at=new arrtest();
at.oper();
at.print();
}
}

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More General Aptitude Interview Questions

Two planes take off at the same exact moment. They are flying across the Atlantic Ocean. One leaves New York and is flying to Paris at 800 km/hr. The other leaves Paris and is flying to New York at only 750 km/hr ( because of a strong head wind ). Which one will be closer to Paris when they meet?

3 Answers   Wipro, Zarca Interactive,


the word unimpressive was given.they asked us to do change 1st & 2nd,3rd & 4th,so on.then they asked what will be 10th letter from right?

0 Answers   Accenture,


A farmer needs to divide 8 gallons into two equal parts. He has 2 other containers. A 5 gallon and a 3 gallon. All our irregularly shaped.

2 Answers  


Placement aptitude questions pattern in oyo rooms

0 Answers   OYO Rooms,


In a single throw of two dice, find the probability of getting a total of 9 or 11

4 Answers  


In a certain code, TERMINAL is written as SDQIJOBM. How is CREDIBLE written in that code? (a) BQDCJCMF (b) DSFEJCMF (c) BQDCHAKD (d) DSFEHAKD (e) None of these

9 Answers  


pls send me sbi previous solved papers through my email

0 Answers  


What is the value of 12x-3x-7 when x =-5?

3 Answers   eClerx,


f(X)=4f(X-1) THEN VALUE OF X=

0 Answers   CTS,


falling height is proportional to square of the time. one object falls 64cm in 2sec than in 6sec from how much height the object will fall.

0 Answers   Accenture,


In the series 0, 3, 8, 15,__ What is the next number?

0 Answers   Hexaware,


there is a matrix N x N .Its elements consist of either value =1 or value=0. If there is a any zero in the row, then the output matrix should have all zeroes in that row. If there is a single zero in any column then that column should have all zeroes n the output matrix. write the function to perform these operations. i want a solution in c/c++ language

0 Answers   Nagarro,


Categories