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
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 |
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 |
directly send to me an questionfirst next line answers or printout types.the 2007 aptitude questions send to me plz
Give me aptitude questions which generally asked in eclerx company in aptitude test.
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?
i need last 5yr sbi question paper. i have exam on 6th july.plz send me
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?
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 ?
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?
A beats B by 10 meters and B beats C by 15 metres the A beats C by
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
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
Editor:magazine ::
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?