There are specific steps you need to follow to solve a problem, in other words, write a C program.
- Determine the objective or objectives of the program
- Determine the methods you want to use in writing program
- Create the program to solve the problem
- Run the program to see results
Let’s simplify this using an example. Imagine you need to write a program to calculate the area of a circle. Let’s begin.
Step 1 is completed because you already know the objective: Calculate the area of a circle. Step 2 is a method to solve this problem. Assume the radius of the circle is input by the user. So you need to calculate the area using πr2.
Step 3 is writing the C program.
#include <stdio.h>
#define pi 3.1415
int main()
{
int r;
printf("Input Radius: ");
scanf("%d",&r);
printf("The area : %.3f\n",pi*r*r);
}
Step 4 is run the program and see results. You can try this online or offline.
Happy coding 😀. See you…