156k views
0 votes
Write a program that stores the value 16 in the variable length and the value 18 in the variable width. Have your program calculate the value assigned to the variable perimeter using the formula perimeter = 2 * length + 2 * width. Have your program print the value stored in perimeter.

User Entesar
by
4.9k points

1 Answer

6 votes

Answer:

#include<iostream>

using namespace std;

int main()

{

int length = 16;

int width = 18;

int perimeter = (2*length) + (2 * width);

cout<<"The perimeter is: "<<perimeter<<endl;

}

Step-by-step explanation:

First include the library iostream in the c++ program for input/output.

then, create the main function and define the variable with given values in the length and width.

After that calculate the perimeter by using the formula.

perimeter = 2*length + 2*width

and finally display the output on the screen by using the cout instruction.

User Bro
by
5.8k points