🔥Hot:

pointer multiplication c++ example source code

Write a program in c++ programming to multiply two numbers using pointers.
Make a function for multiplication that takes input from the user. 

There should be three functions and each should return a different data type int, float and double.

Prototypes for functions are



This program has been tested on c++ code blocks IDE
C++ source code:
see also: pointer addition example source code

#include <iostream>
using namespace std;

int
Mult(int *, int *);
float
Mult1(int *, int *);
double
Mult2(int *, int *);

int
main(){

int
a,b;

cout<<"Enter 1st Value:";
cin>>a;
cout<<"Enter 2nd Value:";
cin>>b;
cout<<"...............Multiplication.........." <<endl <<endl;

cout<<"The integer Multiplication of these numbers is:"<<Mult(&a,&b)<<endl;
cout<<"The float Multiplication of these numbers is:"<<Mult1(&a,&b)<<endl;
cout<<"The double Multiplication of these numbers is:"<<Mult2(&a,&b)<<endl;

cout<<endl <<endl;
return
0;
}


int
Mult(int *x, int *y){
int
Prod;
Prod=(*x * *y);
return
Prod;
}


float
Mult1(int *x, int *y){
float
Prod;
Prod=(*x * *y);
return
Prod;
}


double
Mult2(int *x, int *y){
double
Prod;
Prod=(*x * *y);
return
Prod;
}


Program input-output

If you don't want to write prototypes then just add three methods above the main method. 

Suggestion number 1

I suggest first remove the prototypes then examine the errors the c++ compiler (IDE) will show. This will help to understand errors also. 

Suggestion number 2

We have 3 methods with all methods take two integers as arguments. Try by changing argument data types and return types and examine the different cases in which your code is working and not working. 

Always keep doing experiments with the code for fast learning.
Each and every time you face an error you learn.

Read also: c++ programming simple examples



Previous Post Next Post