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 |
who said that " Divide and rule "
If a light flashes every 6 seconds, how many times will it flash in ¾ of an hour?
inept : clever :: languid :
please send the marketing aptitude,computer knowldege for sbi clerical exam ........
0 Answers NFL, State Bank Of India SBI,
Want to get some material for apptitud e for banking preparation
the number of shells in a judys collection is 80% of the numbers justins collection if justin has 80 more shells than judy how many shells do they have together
There are four dogs/ants/people at four corners of a square of unit distance. At the same instant all of them start running with unit speed towards the person on their clockwise direction and will always run towards that target. How long does it take for them to meet and where?
8 Answers Microsoft, Panasonic,
if ELECTRICITY - GAS =100 then JACK - JILL = ?
5 Answers Citicorp, COSL, TWWI, Wipro,
After spending 2/3 of his salary on rent and food items and 1/4th of the remaining on transportation, Rajesh has 6000 with him. How much did he pay on transportation?
If VXUPLVH is written as SURMISE, what is SHDVD?
which one of the following nutrients is not a structural components of the plant
COMPLETE THE SERIES 19 48 30 96.... A.144 B. 192 C.160 D. NONE OF THESE