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

A coin with p(head)=0.6 is tossed twice.What is the probability that at least one head occurs?

1 Answers  


How much is 3/7 larger than 20 percent of 2

1 Answers   DSQ Software,


If the word FADENCOMT equals 345687921 then What is FEAT. Find representation of 2998

0 Answers   Flipkart,


A person went to shop and asked for change for 1.15 paise. But he said that he could not only give change for one rupee but also for 50p, 25p, 10p and 5p. What were the coins he had ?

0 Answers   HCL, Infosys,


What is the angle between the two hands of the clock when it shows 10:10?

0 Answers   CGI,


If A=Z, B=Y, C=X, .......... Z=A, Then ZERD = ?

0 Answers   Baan Infotech,


A sales person multiplied by a number and get the answer 3. Instead of that number divided by 3. What is the answer she actually has to get. (1/3) * 1 *3 =3 so the no= 1 divided by three.

0 Answers   Accenture, TCS,


if x=y=2z and xyz =256 then x=

0 Answers  


One ship goes along the stream direction 28 km and in opposite direction 13 km in 5 hrs for each direction.What is the velocity of stream? `

0 Answers   Accenture,


There are 1000 doors that are of the open-close type. When a person opens the door he closes it and then opens the other. When the first person goes he opens-closes the doors ion the multiples of 1 i.e., he opens and closes all the doors. When the second goes he opens and closes the doors 2, 4 6 8 rely. Similarly when the third one goes he does this for 3 6 9 12 15th doors rely. Find number of doors that are open at last.

0 Answers   Accenture,


For a user to be able to choose an option from a dropdown list, what would you set as they allow settings in the data validation settings tab in excel? a) list B) rigion c) Option d) range

2 Answers   eClerx,


In a pond ecosystem, large fishes and small fishes will be there. If we want to remove small amount of pollutants, small fishes are to be employed. In a food chain food passes through a number of mouths and en route the mouth of the super feeder-the eagle. Its population determines the size of the ecosystem. But this has been proved false.What can you infer from above? (4 choices)

0 Answers   Accenture,


Categories