Friday, 23 January 2015

Program to enter the element in array at Nth position in C++

//Program to enter the element in array at Nth position.

#include<iostream.h>
#include<conio.h>
void main()
{
 int a[10],i,j,m,n,k;
 clrscr();
 cout<<"Enter the length of array:\n";
 cin>>n;
 cout<<"Enter no of elements:\n";
 for(i=0;i<n;i++)
 cin>>a[i];
 cout<<"Enter the position k:\n";
 cin>>k;
 cout<<"Enter the element you want to insert:\n";
 cin>>m;
 for (j=n;j>=k-1;j--)
   {
    a[j+1]=a[j];
    a[j]=m;
   }
   n=n+1;
   for(i=0;i<n;i++)
   cout<<"\n"<<a[i];
  getch();
 }

No comments:

Post a Comment

Read contacts in iOS using Swift with error handling

Just copy and paste the below code Pre-step before pasting the below code Add below line in AppDelegate.swift file below import statement ...