Skip to main content

How to take integer as input into an array and decorate them in increasing order in C++ language??? // Sorting an Array

First taking integers randomly as input into an array then decorate those in increasing order

#include<iostream> using namespace std; int main() { int n; cin>>n; int arr[n]; for(int i=0;i<n;i++) { cin>>arr[i]; } cout<<"After getting input "<<endl; for(int i=0;i<n-1;i++) { for(int j=0;j<n;j++) { if(arr[j]>arr[j+1]) { swap(arr[j],arr[j+1]); } } } for(int i=0;i<n;i++) { cout<<arr[i]<<" "; } return 0; }

Quote: “There is nothing more dreadful than the habit of doubt. Doubt separates people. It is a poison that disintegrates friendships and breaks up pleasant relations. It is a thorn that irritates and hurts; it is a sword that kills.” ― Buddha Siddhartha Guatama Shakyamuni