C Online Compiler
Example: Rectangle Measurement in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Rectangle Measurement #include <stdio.h> void calculateRectangle() { float length, width, area, perimeter; printf("\n--- Rectangle Calculator ---\n"); printf("Enter the length of the rectangle: "); scanf("%f", &length); printf("Enter the width of the rectangle: "); scanf("%f", &width); if (length <= 0 || width <= 0) { printf("Error: Length and width must be positive values.\n"); return; } area = length * width; perimeter = 2 * (length + width); printf("Area of the rectangle: %.2f\n", area); printf("Perimeter of the rectangle: %.2f\n", perimeter); }
Output
Clear
ADVERTISEMENTS