eguruchela

FAQ : Computer>C program

Write a C++ Program to store 5 numbers entered by user in an array and display the first and last entered number only?

C++ Program

#include <iostream> 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:
7
12
8
-7
2
First number: 7
Last number: 2

Previous Page        Next Page

Programing with C