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

The ratio of the number of boys and girls in a college is 3:2. Out of these 10 percent are boys and 25 percent are girls are scholarship holders. Find the no of boys and girls who are not scholarship holders.

0 Answers   3i Infotech,


If the ticket sales s for a company increases 25% from standard sales to 60 tickets sold, then 60-s=

1 Answers  


Hi... this is pankaj (final yr chemical engg)..i am appearing for officer trainee exam at 22nd feb.. plz tell me which book to refer for hpcl exam aptitude test and plz help if anyone has any clue about technical test..mail me at pankajbhole07@gmail.com.............

0 Answers  


WHERE IS THE HEADQUARTER OF WORLD TRADE ORGANIZATION(WTO)

5 Answers   Bhel, SSC,


How many 3-digit numbers with atleast one 5 in their digits?

0 Answers   Huawei,


1) In the class of 40 students, 30 speak Hindi and 20 speak English. What is the lowest possible number of students who speak both the languages? (a) 5 (b) 20 (c) 15 (d) 10 (e) 30

11 Answers   TCS,


The ratio for Boys to Girls is 6:4. 60% of the boys and 40% of girls take lunch in the canteen. What % of class takes lunch in canteen.

0 Answers   Infosys,


It takes five minutes to pass a rumor from one person to two other persons. The tree of rumor continues. Find how many minutes does it take spread the rumor to 768 persons.

0 Answers   Accenture,


A works thrice as much as B. If A takes 60 days less than B to do a work then find the number of days it would take to complete the work if both work together?

0 Answers   3i Infotech, Canara Bank, EDS,


Five people A ,B ,C ,D ,E are related to each other. Four of them make one true statement each as follows. (i) B is my father's brother. (ii) E is my mother-in-law. (iii)C is my son-in-law's brother (iv)A is my brother's wife.

1 Answers   Infosys,


A man gets x/y of Rs.10 and y/x of Rs.10. He returns Rs.20. The Answer choices are a) He may not lose b) He may lose c) He always loses d) Cannot be Determined

2 Answers   CTS,


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,


Categories