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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of dot in c++?

712


What is the difference between map and hashmap in c++?

659


What is == in programming?

702


What is dev c++ used for?

688


If a header file is included twice by mistake in the program, will it give any error?

646






What is a multiset c++?

664


What is object in c++ wikipedia?

644


Can a new be used in place of old mallocq? If yes, why?

718


What is c++ flowchart?

782


What is math h in c++?

689


What is the auto keyword good for in c++?

720


What is an operator in c++?

695


What is a wchar_t in c++?

690


Define a pdb file.

729


What are the advantages of using typedef in a program?

727