1.
Program to insert 10 elements in an array and print the value of 7, 8,
9th element of that array.
Pseudo code:
1. First declare an array named “array” for 10 elements.
2. Start for(int i = 0; i < 10; i++).
3. Inside the loop input values for the array.
4. Start for(int i = 6; i < 9; i++).
5. Inside the loop print the values of 7th, 8th and 9th elements of the array.
#include<iostream>
using namespace std;
int main(){
int array[10];
for(int i = 0; i < 10; i++){
cin>>array[i];
for(int i = 6; i < 9; i++){
cout<<"The "<<i + 1<<"th element is: "<<array[i]<<endl;
To declare an array, we have to declare a data type just like int keyword and then
the array’s name. After the name, inside a square bracket, we should define the
number of elements. In the 1st for loop started from 0 to 9, use cin object to have
inputs for the array elements.
In the 2nd for loop started from 6 to 8, use cout object to get the outputs of 7th, 8th
and 9th elements.
In output, the first 10 lines are the elements of the array. Then the last 3 lines are
the 7th, 8th and 9th elements of the array. Cause we can see from the first 10 lines,
The 7th, 8th and 9th elements of the array are 14, 34 and 76.
2. Program to insert 13 elements in an array and print the value of
4,6,11th index of that array.
Pseudo code:
1. First declare an array named “array” for 13 elements.
2. Start for(int i = 0; i < 13; i++).
3. Inside the loop input values for the array.
4. Print the values of 4th, 6th and 11th index of the array.
#include<iostream>
using namespace std;
int main(){
int array[13];
for(int i = 0; i < 13; i++){
cin>>array[i];
cout<<"The value of 4th index: "<<array[4]<<endl;
cout<<"The value of 6th index: "<<array[6]<<endl;
cout<<"The value of 11th index: "<<array[11]<<endl;
To declare an array, first we have to declare a data type just like int keyword and
then the array’s name. After the name, inside a square bracket, we should define the
number of elements. In the 1st for loop started from 0 to 12, use cin object to have
inputs for the array elements.
We should use cout object to get output of the values of 4th, 6th and 11th index from
the array. At the end of every statement, we used endl object to create a new line.
In output, the first 13 lines are the elements. Then the last 3 lines are the values of
4th, 6th and 11th index of the array. We got 65, 12 and 23. Because when the index is
4, it will show the 5th element from the array. On the same way, we got 12 and 23 as
the values of 6th and 11th index.
3. Program to insert 5 elements in an array and print all the elements of
that array.
Pseudo code:
1. First declare an array named “array” for 5 elements.
2. Start for(int i = 0; i < 5; i++).
3. Inside the loop input values for the array.
4. Start for(int i = 0; i < 5; i++) again.
5. Inside the loop print the values of the array.
#include<iostream>
using namespace std;
int main(){
int array[5];
for(int i = 0; i < 5; i++){
cin>>array[i];
for(int i = 0; i < 5; i++){
cout<<"The no."<<i + 1<<" element is: "<<array[i]<<endl;
To declare an array, first we have to declare a data type just like int keyword and
then the array’s name. After the name, inside a square bracket, we should define the
number of elements. In the 1st for loop started from 0 to 4, use cin object to have
inputs for the array elements.
In the 2nd for loop started from 0 to 4, use cout object to get the outputs of
elements.
In output, first 5 lines are the elements and the last 5 lines are the output of the
elements.