Code Competitions

Coding competition

Friday, 31 May 2013

program to use pointer as array and modify

#include<iostream.h>
#include<conio.h>
void main()
{
    int i,n,*a,*b;
    void modify(int *,int);
    clrscr();
    a=b;
    cout<<"how many elements ";
    cin>>n;
    cout<<"enter the elements\n";
    for(i=0;i<n;i++)
    {
        cout<<"\na["<<i<<"]=";
        cin>>*(a+i);
    }
    cout<<"enter the array elements are \n";
    for(i=0;i<n;i++)
    {
        cout<<"\na["<<i<<"]="<<*(a+i);
    }
    modify(a,n);
    cout<<"elements after manipulation \n";
    for(i=0;i<n;i++)
    {
        cout<<"\na["<<i<<"]= "<<*(a+i);
    }
    getch();
}
void modify(int *a,int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        *(a+i)=(*(a+i))+500;
    }
}

No comments:

Post a Comment