This program finds the cube of a number in C++. The number is read as input and is stored is the variable n. The program uses a void pointer which points to n. The statement int *pint= (int *)p; stores the value at p to the pointer variable pint. Then the program repeatedly multiples pint 3 times which gives the cube of the given number.
Program
#include<iostream.h> #include<conio.h> void main() { int n; void *p; p=&n; cout<<"Enter the number"; cin>>n; int *pint= (int *)p; n=(*pint)*(*pint)*(*pint); cout<<"Cube of the number is\n"; cout<<n; getch(); }
No comments:
Post a Comment