C Programming Code Examples C > Beginners Lab Assignments Code Examples C program to find perimeter of a rectangle C program to find perimeter of a rectangle Write a C program to input length and width of a rectangle and calculate perimeter of the rectangle. How to find perimeter of a rectangle in C programming. Input length and width of the rectangle using scanf() function. Store it in two variables say length and width. Calculate perimeter using formula for perimeter of rectangle perimeter = 2 * (length + width). Print the value of perimeter. #include <stdio.h> int main() { float length, width, perimeter; /* * Input length and width of rectangle from user */ printf("Enter length of the rectangle: "); scanf("%f", &length); printf("Enter width of the rectangle: "); scanf("%f", &width); /* Calculate perimeter of rectangle */ perimeter = 2 * (length + width); /* Print perimeter of rectangle */ printf("Perimeter of rectangle = %f units ", perimeter); return 0; }