C++ PROGRAM-GIVE COMMENTS (HOW THE CODE SOLVED i.e logics) ON EACH LINE OF THE CODE BELOW. ACTUAL QUESTION: Write a program to insert an element at 17th index in an array of 20 elements. Take all elements from user and display the output. NOTE: IF YOU CAN'T ADD COMMENTS ON THIS CODE THEN DO ANOTHER CODE AND ADD COMMENTS ON THAT PLEASE. THANKS CODE: #include using namespace std; int main() { cout<<"\n\n"; int arr[20],num; cout<<"Enter 20 numbers: "; for (int i = 0; i < 20; i++) { cin>>arr[i]; } cout<<"Enter 17th element: "; cin >> num; cout<<"\nArray before changing 17th element: \n"; for (int i = 0; i < 20; i++) { cout << arr[i] << " "; } arr[16] = num; cout << "\nArray after changing 17th element: \n"; for(int i=0;i<20;i++) { cout<
C++ PROGRAM-GIVE COMMENTS (HOW THE CODE SOLVED i.e logics) ON EACH LINE OF THE CODE BELOW.
ACTUAL QUESTION: Write a program to insert an element at 17th index in an array of 20
elements. Take all elements from user and display the output.
NOTE: IF YOU CAN'T ADD COMMENTS ON THIS CODE THEN DO ANOTHER CODE AND ADD COMMENTS ON THAT PLEASE. THANKS
CODE:
#include <iostream>
using namespace std;
int main()
{
cout<<"\n\n";
int arr[20],num;
cout<<"Enter 20 numbers: ";
for (int i = 0; i < 20; i++)
{
cin>>arr[i];
}
cout<<"Enter 17th element: ";
cin >> num;
cout<<"\nArray before changing 17th element: \n";
for (int i = 0; i < 20; i++)
{
cout << arr[i] << " ";
}
arr[16] = num;
cout << "\nArray after changing 17th element: \n";
for(int i=0;i<20;i++)
{
cout<<arr[i]<<" ";
}
cout << "\n\n";
return 0;
}
Step by step
Solved in 2 steps with 1 images