We can make the program to calculate a formula.
For example: to multiply x and y variables.
We have to define the variable first, then write the formula, and the last, print the result with cout<<.
See the example below:
#include “iostream.h”
#include “conio.h”
Main()
{
int x, y, z;
cout<<”insert a number for X : ”;
cin>> x;
cout<<”insert a number for Y : ”;
cin>> y;
z = x * y;
cout<< x << “ * ” << y << “ = ” << z;
getch();
}
See and learn the picture below:
We can change the formula become other one. But the important things to remember are to define the formula as a variable and then we can simply to print that variable.
0 comments:
Post a Comment