Things you must know before writing the first C program

There are specific steps you need to follow to solve a problem, in other words, write a C program.

  1. Determine the objective or objectives of the program
  2. Determine the methods you want to use in writing program
  3. Create the program to solve the problem
  4. 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…

1
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x