C++ Program to store 5 numbers entered by user in an array and display first and last number only.


Levels of difficulty: / perform operation:

C++ Program

#include <iostream>

 using namespace std;
int main() {
int n[5];
cout<<"Enter 5 numbers: ";
/* Storing 5 number entered by user in an array using for loop. */
for (int i = 0; i < 5; ++i) {
cin>>n[i];
}
cout<<"First number: "<<n[0]<<endl;
// first element of an array is n[0]
cout<<"Last number: "<<n[4];
// last element of an array is n[SIZE_OF_ARRAY - 1]
return 0;
}
output :Enter 5 numbers: 4
-3
5
2
0
First number: 4
Last number: 0





Quantitative Aptitude
Reasoning
Programming
Interview