C Tutorial

This c porgram is used to compute the perimeter of a square based on user input length.

Length is equal for each side in square.

Perimeter of a square: length + length + length + lengthor

Perimeter of a square: 4 x length

// Finds perimeter of a triangle #include<stdio.h> void main() { int length, perimeter=0; printf("\nFinds perimeter of a square\n-------------------"); printf("\nEnter Length: "); scanf("%d", &length); perimeter = 4 * length; printf("Perimeter of a square is: %d", perimeter); }

Output:

$ cc perimeter-of-square.c $ ./a.out Finds perimeter of a square ------------------- Enter Length: 6 Perimeter of a square is: 24

#include<stdio.h> void main() { int length, perimeter=0; printf("\nFinds perimeter of a square\n-------------------"); printf("\nEnter Length: "); scanf("%d", &length); perimeter = (length + length + length + length); printf("Perimeter of a square is: %d", perimeter); }

Output:

$ cc perimeter-of-square.c $ ./a.out Finds perimeter of a square ------------------- Enter Length: 6 Perimeter of a square is: 24

C Program Examples

C Tutorial

Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page

^