Tous les défis
Facile 1 résolu 100.0 % de réussite

Rectangle Perimeter

Compute the perimeter of a rectangle from its sides.

Problème

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.

Contraintes

1 ≤ width, height ≤ 1,000,000

Exemples

Exemple 1
Entrée :
width = 3
height = 5

Sortie attendue :
expected = 16
Entrée :
long long width = 3;
long long height = 5;

Sortie attendue :
long long expected = 16;
Entrée :
long width = 3;
long height = 5;

Sortie attendue :
long expected = 16;

Explication

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

Exemple 2
Entrée :
width = 7
height = 7

Sortie attendue :
expected = 28
Entrée :
long long width = 7;
long long height = 7;

Sortie attendue :
long long expected = 28;
Entrée :
long width = 7;
long height = 7;

Sortie attendue :
long expected = 28;

Explication

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

Références

Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.

Apprenez des autres

Solutions de la communauté

Attention spoiler : 1 solution complète ci-dessous Essayez d'abord de le résoudre vous-même. Vous pouvez toujours jeter un œil au code des autres développeurs et aux avis IA. Connectez-vous et résolvez le défi pour rejoindre la discussion.