Can someone please explain each line of code with comments n

Can someone please explain each line of code with comments next to them. Thank you

#include<iostream.h>
#include<conio.h>
using namespace std;

main()
{

int hold;
int array[5];
cout<<\"Enter 5 numbers: \"<<endl;
for(int i=0; i<5; i++)
{
cin>>array[i];
}
cout<<endl;
cout<<\"Orignally entered array by the user is: \"<<endl;

for(int j=0; j<5; j++)
{
cout<<array[j];
cout<<endl;
}
cout<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
if(array[j]>array[j+1])
{
hold=array[j];
array[j]=array[j+1];
array[j+1]=hold;
}
}
}
cout<<\"Sorted Array is: \"<<endl;
for(int i=0; i<5; i++)
{
cout<<array[i]<<endl;
}

getch();
}

Solution

#include<iostream.h>
#include<conio.h>
using namespace std;

main()
{

int hold;
int array[5]; //initializing the array
cout<<\"Enter 5 numbers: \"<<endl;
for(int i=0; i<5; i++) //starting of for loop
{
cin>>array[i]; //taking the values of array
}
cout<<endl;
cout<<\"Orignally entered array by the user is: \"<<endl; //prints the originally entered array

for(int j=0; j<5; j++) //for loop
{
cout<<array[j]; //prints the array j
cout<<endl;
}

//checking the values by taking up 2 for loops
cout<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
if(array[j]>array[j+1])
{

//swaping
hold=array[j];
array[j]=array[j+1];
array[j+1]=hold;
}
}
}
cout<<\"Sorted Array is: \"<<endl;

//printing out the sorted array using for loop
for(int i=0; i<5; i++)
{
cout<<array[i]<<endl;
}

getch();
}

Can someone please explain each line of code with comments next to them. Thank you #include<iostream.h> #include<conio.h> using namespace std; main(
Can someone please explain each line of code with comments next to them. Thank you #include<iostream.h> #include<conio.h> using namespace std; main(

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site