1. C++ Program to display the array elements using function and pointers.
#include<iostream>
using namespace std;
void disparr(int[],int);
int main()
int arr[20],n;
cout<<"Enter the size of the array: ";
cin>>n;
cout<<"\n Enter the array elements: ";
for(int i=0;i<n;i++)
cin>>arr[i];
cout<<"The array elements are: "<<endl;
disparr(arr,n);
void disparr(int *j, int size)
for(int i=0;i<size;i++)
cout<<*j<<" ";
j++;
}
2. C++ Program to add two complex numbers using structure.
#include<iostream>
using namespace std;
typedef struct
float real;
float img;
} Complex;
int main()
Complex A,B,C;
cout<<"Enter real and imaginary parts of A: ";
cin>>[Link]>>[Link];
cout<<"Enter real and imaginary parts of B: ";
cin>>[Link]>>[Link];
[Link]=[Link]+[Link];
[Link]=[Link]+[Link];
cout<<"The sum is: "<<[Link]<<"+"<<[Link]<<"i";
3. C++ Program to add two complex numbers using structure and function.
#include<iostream>
using namespace std;
typedef struct
{
float real;
float img;
} Complex;
void sum(Complex &,Complex &);
int main()
Complex A,B;
cout<<"Enter real and imaginary parts of A: ";
cin>>[Link]>>[Link];
cout<<"Enter real and imaginary parts of B: ";
cin>>[Link]>>[Link];
sum(A,B);
void sum(Complex &P, Complex &Q)
Complex C;
[Link]=[Link]+[Link];
[Link]=[Link]+[Link];
cout<<"The sum is: "<<[Link]<<"+"<<[Link]<<"i";
}
4. C++ Program to subtract two complex numbers using structure and function.
#include<iostream>
using namespace std;
typedef struct
float real;
float img;
} Complex;
void diff(Complex &,Complex &);
int main()
Complex A,B;
cout<<"Enter real and imaginary parts of A: ";
cin>>[Link]>>[Link];
cout<<"Enter real and imaginary parts of B: ";
cin>>[Link]>>[Link];
diff(A,B);
void diff(Complex &P, Complex &Q)
Complex C;
[Link]=[Link];
[Link]=[Link];
cout<<"The difference is: "<<[Link]<<"+"<<[Link]<<"i";
5. C++ Program to multiply two complex numbers using structure and function.
#include<iostream>
using namespace std;
typedef struct
float real;
float img;
} Complex;
void mul(Complex &,Complex &);
int main()
Complex A,B;
cout<<"Enter real and imaginary parts of A: ";
cin>>[Link]>>[Link];
cout<<"Enter real and imaginary parts of B: ";
cin>>[Link]>>[Link];
mul(A,B);
void mul(Complex &P, Complex &Q)
Complex C;
[Link]=[Link]*[Link]*[Link];
[Link]=[Link]*[Link]+[Link]*[Link];
cout<<"The product is: "<<[Link]<<"+"<<[Link]<<"i";
6. C++ Program to add two complex numbers using structure pointers.
#include<iostream>
using namespace std;
typedef struct
float real;
float img;
} Complex;
void sum(Complex *,Complex *);
int main()
Complex A,B;
cout<<"Enter real and imaginary parts of A: ";
cin>>[Link]>>[Link];
cout<<"Enter real and imaginary parts of B: ";
cin>>[Link]>>[Link];
sum(&A,&B);
}
void sum(Complex *P, Complex *Q)
Complex C;
[Link]=P->real + Q->real;
[Link]=P->img + Q->img;
cout<<"The sum is: "<<[Link]<<"+"<<[Link]<<"i";
7. C++ Program to show the difference between Structure and Union.
#include<iostream>
using namespace std;
struct Complex1
int real;
float img;
} c1;
union Complex2
int real;
float img;
} u1;
int main()
cout<<"Enter the real and img part of structure: ";
cin>>[Link]>>[Link];
cout<<"The complex number is: "<<[Link]<<"+"<<[Link]<<"i ";
cout<<"\n The size of the structure is: "<<sizeof(c1)<<endl;
cout<<"Enter the real and img part of union: ";
cin>>[Link]>>[Link];
cout<<"The complex number is: "<<[Link]<<"+"<<[Link]<<"i "<<endl;
cout<<"\n The size of the union is: "<<sizeof(u1);
8. C++ program to create a dynamic array using new and delete operators.
#include<iostream>
using namespace std;
int main()
int *p=new int[5];
cout<<"Enter the array elements: ";
for(int i=0;i<5;i++)
cin>>*(p+i);
cout<<"\n The array elements are: ";
for(int i=0;i<5;i++)
cout<<*(p+i)<<" ";
delete []p;