Sei sulla pagina 1di 4

Experiment -10

Title of experiment:- Write a program to add elements in array using pointers.


Aim of experiment:- To understand concept of array and pointers.
Source code:-
#include<iostream>
using namespace std;
#include<conio.h>
int main()
{
int s,i,j;
int a[10];
s=0;
cout<<"enter any 10 values:- "<<endl;
for(i=0;i<10;i++)
{
cin>>a[i];
}
for(j=0;j<10;j++)
{
s=s+ *(a+j);
}
cout<<"sum of array:- "<<s<<endl;
getch();
return 0;
}

1703233 Anurag
Output:-

1703233 Anurag
Experiment -11
Title of experiment:- Write a program to compare elements of 2 arrays using pointers.
Aim of experiment:- To understand concept of array and pointers.
Source code:-

#include<iostream>
using namespace std;
#include<conio.h>
int main()
{
int i,j,c,r=0;
int a[5],b[5];
for(i=0;i<5;i++)
{
cout<<"enter value of a"<<endl;
cin>>a[i];
}
for(j=0;j<5;j++)
{
cout<<"enter value of b"<<endl;
cin>>b[j];
}
for (c=0;c<5;c++)
{
if(*(a+c) == *(b+c))
{
r=r+1;
continue;
}
}
if (r==5)
{
cout<<"array are equal";
}
else
{
cout<<"array are not equal";
}
getch();
return 0;
}

1703233 Anurag
Output:-

Case-1 (When arrays are not equal)

Case-2(When array are equal)

1703233 Anurag

Potrebbero piacerti anche