Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3922237 • Letter: C

Question

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();
}

Explanation / Answer

#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();
}