# How do you write algorithm in c-program?

Here is a simple program that will tell you how to make an algorithm:

int main();

{

int length;

int width;

int total;

printf("What is the width: ");

scanf("%d", &width);

printf("What is the length: ");

scanf("%d", &length);

total = width * 2 + 2 * length; /*Here is the algorithm for finding the perimeter of a square*/

printf("The perimeter is: %d", total);

return 0;

}

Output:

What is the width: 32

What is the length: 55

The perimeter is: 174

### Is it mandatory to write an algorithm before every program?

Not every program, no. An algorithm describes the procedural steps required to solve a particular problem using natural language. A program usually consists of many such algorithms, each of which can be defined as a function or a series of functions encapsulated by a class. The more trivial the function the less likely you need to write an algorithm.