Thursday 26 June 2014

C++ program to print element at given position in an array


Here is a C++ program to print element at given position in an array


 SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
    int a[20],num,n;
    cout<<"How many elements to be stored (max 20) : ";
    cin>>num;
    cout<<"Enter elements ";
    for(int i=0;i<num;i++)
       cin>>a[i];
    cout<<"Enter value of n : ";
    cin>>n;
    cout<<"Element at "<<n<<"th position : "<<a[n-1];
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment