You have to take 2 arrays of length 10. Input the values of
array 1 from the user. Then copy the values of array 1 to
array 2 in ascending order

For example if user enters 9, 5, 6, 8, 1, 0, 2, 7, 4, 3
then copy the smallest element i.e. 0 first followed by 1,
2 and so



You have to take 2 arrays of length 10. Input the values of array 1 from the user. Then copy the v..

Answer / prasenjit roy

#include "stdio.h"
#include "conio.h"

int main(int argc, char* argv[])
{
int arr[]={9, 5, 6, 8, 1, 0, 2, 7, 4, 3},i,j,iTmp;
printf("original :: ");
for ( i = 0; i < sizeof(arr)/sizeof(int) ; i++)
printf("%d, ",arr[i]);
printf("\b\b \n");

for ( j = 0; j < sizeof(arr)/sizeof(int) -2; j++ )
{
for ( i = sizeof(arr)/sizeof(int) -1; i >
j ; i-- )
{
if ( arr[i] < arr[j] )
{
iTmp = arr[j];
arr[j] = arr[i];
arr[i] = iTmp;
}
}
}

printf("modified :: ");
for ( i = 0; i < sizeof(arr)/sizeof(int) ; i++)
printf("%d, ",arr[i]);
printf("\b\b \n");

while( ! _kbhit() );
return 0;
}

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More C++ General Interview Questions

What do you mean by global variables?

0 Answers  


What is data hiding c++?

0 Answers  


what is smart pointer & use of the smart pointer ???

2 Answers  


What is friend class in c++ with example?

0 Answers  


Can create new c++ operators?

0 Answers  






What is difference between n and endl in c++?

0 Answers  


What is the best way to declare and define global variables?

0 Answers  


What is pointer in c++ with example?

0 Answers  


What are default parameters? How are they evaluated in c++ function?

0 Answers  


Why would you make a destructor virtual?

3 Answers   Lehman Brothers,


Do vectors start at 0 c++?

0 Answers  


Should I learn c++ c?

0 Answers  


Categories