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

how 1000000000 can be written as a product of two factors neither of them containing zeros

0 Answers   Infosys,


Number Series 7,16,9,15,11,14,?

15 Answers   TCS,


A bus has 40 seats and the passengers agree to share the total bus fare among themselves equally. If the total fair is 80.67 , find the total no of the seats unoccupied.

4 Answers   Accenture, CTS,


If a:b=5:6 and b:c=5:6, a:c=?

3 Answers   eClerx, Infosys,


The minimum number of digits required to form every number which is greater than 900 and less than 9,000 is:

0 Answers   Wipro,


A man bought some fruits at the rate of 16 for Rs. 24 and sold them at the rate of 8 for Rs. 18. What is the profit per cent? (a) 50% (b) 60% (c) 40% (d) 25% (e) None of these

9 Answers  


9 laboures can complete the construction of a wall in 18 days. How many less days will 12 laboures take to complete the same wall?

1 Answers   Wipro,


Hi frds, can any one send me previous soved question papers of SBI clerical post....my mail id is venky.lotus@gmail.com...Thanks in Advance

0 Answers  


The crew of a rowing team of 8 members is to be chosen from 12 men (M1, M2, …., M12) and 8 women (W1, W2,…., W8), such that there are two rows, each row occupying one the two sides of the boat and that each side must have 4 members including at least one women. Further it is also known W1 and M7 must be selected for one of its sides while M2, M3 and M10 must be selected for other side. What is the number of ways in which rowing team can be arranged.

0 Answers   TCS,


The LCM of two numbers is 75. The GCF is 5. The sum of the numbers is 40. What are the numbers?

8 Answers  


12 revolutions takes 1/8 th second time.In 20 seconds how many revolutions?

7 Answers   Citi Bank, CitiGroup, Ramco,


A company rented a machine for Rs.700/- a month. Five years later the treasurer calculated that if the company had purchased the machine and paid Rs.100/- monthly maintenance charge, the company would have saved Rs.2000/-. What was the purchase price of the machine?

3 Answers   IBM, TCS,


Categories