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

directly send to me an questionfirst next line answers or printout types.the 2007 aptitude questions send to me plz

1 Answers   Infosys,


Give me aptitude questions which generally asked in eclerx company in aptitude test.

0 Answers  


Two cars travel in the same direction at 40km/hr at a regular distance. A car comes in the opposite direction at 60km/hr. It meets each car in a gap of 8 seconds. What is the distance between the two cars?

14 Answers   Bhel,


i need last 5yr sbi question paper. i have exam on 6th july.plz send me

5 Answers  


2. The school committee of a small town wanted to determine the average children per household of the town. They divided the total no. of children in the town by total no. of households. Total no. of households = 50. Which of the following statements must be true if the average children per household are 2.2?

2 Answers   Mu Sigma, TCS,


The ratio of the length : breadth : height of a cuboid is 5 : 4: 3, and the volume is 7500. What will be its surface area ?

0 Answers   Hexaware,


A man walks around a rectangle. The time taken by him in travelling the length is twice as taken in travelling the breadth of the rectangle. If the perimeter of the rectangle is 300 mts, what is the area of the rectangle?

0 Answers   CGI,


A beats B by 10 meters and B beats C by 15 metres the A beats C by

0 Answers   Accenture,


70% of people reads morning news paper 40% of people reads evening newspaper 20% of people reads neither morning nor evening newspapers 1 prob who reads at least one newspaper 2 prob who reads both newspaper 3 prob who reads only one newspaper

7 Answers   HP, TCS,


If on an item a shop gives 25% discount, they earn 25% profit. If they now give 10% discount then what is the profit percentage

27 Answers   Deloitte,


Editor:magazine ::

0 Answers  


Three friends divided some bullets equally. After all of them shot 4 bullets the total number of bullets remaining is equal to the bullets each had after division. Find the original number divided?

4 Answers  


Categories