google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a C++ program to sort the elements of the array - 2nd puc computer science

Write a C++ program to sort the elements of the array

/*Write a C++ program to sort the elements of the array.*/

#include<iostream.h>

#include<conio.h>

void main( )

{

int a[50], i, temp, n, j;

clrscr( );

cout<<"Enter the number of elements:";

cin>>n;

cout<<"Enter the elements:\n";

for(i=0; i<n; i++)

cin>>a[i];

for(i=0; i<n; i++)

for(j=i+1; j<n; j++)

if(a[i] > a[j])

{

temp = a[i];

a[i] = a[j];

a[j] = temp;

}

cout<<"The sorted elements are:\n";

for(i=0; i<n; i++)

cout<<a[i]<<"\n";

getch( );

}

Write a C++ program to sort the elements of the array Write a C++ program to sort the elements of the array Reviewed by Vision Academy on February 27, 2022 Rating: 5

No comments:

CheckOut

Powered by Blogger.