Todos os desafios
Fácil 1 resolvido 100.0% de aceitação

Rectangle Perimeter

Compute the perimeter of a rectangle from its sides.

Problema

A rectangle has two sides of length width and two sides of length height. Its perimeter is the total length of all four sides.

Implement rectangle_perimeter(width, height).

Input

width: The width of the rectangle. height: The height of the rectangle.

Output

Return the perimeter as an integer.

Restrições

1 ≤ width, height ≤ 1,000,000

Exemplos

Exemplo 1
Entrada:
width = 3
height = 5

Saída esperada:
expected = 16
Entrada:
long long width = 3;
long long height = 5;

Saída esperada:
long long expected = 16;
Entrada:
long width = 3;
long height = 5;

Saída esperada:
long expected = 16;

Explicação

Two sides of 3 and two sides of 5: 3 + 3 + 5 + 5 = 16.

Exemplo 2
Entrada:
width = 7
height = 7

Saída esperada:
expected = 28
Entrada:
long long width = 7;
long long height = 7;

Saída esperada:
long long expected = 28;
Entrada:
long width = 7;
long height = 7;

Saída esperada:
long expected = 28;

Explicação

A square is a rectangle too: 4 × 7 = 28.

Referências

Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.

Aprenda com outros

Soluções da comunidade

Atenção: 1 solução completa abaixo Tente resolver sozinho primeiro. Você ainda pode espiar o código de outros desenvolvedores e as avaliações da IA. Entre e resolva o desafio para participar da discussão.