Here is a C++ program to print first and last element of an array
SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
int a[20],num;
cout<<"How many elements to be stored (max 20) : ";
cin>>num;
cout<<"Enter elements of array a1 : ";
for(int i=0;i<num;i++)
cin>>a[i];
cout<<"First element : "<<a[0]<<endl;
cout<<"Last element : "<<a[num-1];
return 0;
}
using namespace std;
int main()
{
int a[20],num;
cout<<"How many elements to be stored (max 20) : ";
cin>>num;
cout<<"Enter elements of array a1 : ";
for(int i=0;i<num;i++)
cin>>a[i];
cout<<"First element : "<<a[0]<<endl;
cout<<"Last element : "<<a[num-1];
return 0;
}
Any questions regarding to program please write in comments.
No comments:
Post a Comment