¤ Home » Programming » Beginners guide to writing Programs

Beginners guide to writing Programs

What is a program?

A program is a set of instructions given to the computer system to perform certain operations on one or more input data to produce one or more output.

The instructions must be

It is to be noted that a program works on some input data & produces some results in the form of data.

A programmer, when he gets on to write a program, need to practice certain discipline while writing a program. What do we mean by this?

The programmer should never be in a hurry to begin writing the program with the syntax of the language be it C, Pascal, Basic or any other programming language. The given problem must be analyzed first and a logical procedure to solve the problem should be written in the English language, a language that you are conversant with, so that you can focus completely on the solution. This is what we call an ALGORITHM.

While writing an ALGORITHM, the focus of the programmer is solely on identifying & writing down the procedure or set of instructions needed to solve the given problem.

The next step is to represent the procedure written, pictorially, i.e. to convert the procedure or set of instructions, viz. the algorithm, in a pictorial form. This enables the programmer to comfortably review his logic and correct any errors made while writing the algorithm. This pictorial representation is called a FLOW CHART. Here the focus is on the logical flow of data (viz. the inputs) which are to be processed by the program to produce the desired output(s).

Flow charts comprise an important part of the program documentation and can become very useful for future reference as well, whenever a bug is encountered and also whenever the program needs to be updated or modified.

After having drawn the Flow chart(s), it is good practice to represent the flowchart in the form of PSEUDO CODE. A pseudo code, as the name suggests, is very close to the actual code in which you will eventually write your program. However, while writing the pseudo code you are not bogged down by the syntax of the programming language, to which you are new, and your focus is solely on preparing the program outline/structure with the help of the flow chart already drawn. The only thing is that now you are representing it in a language that is much closer to the programming language format but without getting too concerned about the detailed syntax.

Let us consider a simple example to understand what we mean by -


THE PROBLEM: Find the area of a circle, given the numerical value of its radius.

STEP 1: The ALGORITHM to solve this problem
Step1: start
Step2: Read the numerical value of radius of circle
Step3: Calculate the area using the formula A = r2.
Step4: Print the values of radius and the corresponding area.
Step5: Stop

STEP 2: Pictorial representation of the solution in the form of a FLOW CHART

declare a,r as float
read r
a := 3.14 * r * r
print r
print a

STEP 4: The final PROGRAM written in C language

Now you are ready to write the actual program in the programming language of your choice - in this case it is C. Since you have already finalized your program structure while writing the pseudo code, at this stage your focus is solely on the programming language syntax. You focus here in writing the program in the correct syntax so that there are no errors.

Note that in the example below, we have added comments so that you can understand what each line does and compare it with your pseudo code.

#include<stdio.h> // Include standard input-output library for printf & scanf functions
#include<math.h> // Include the math library to use the constant PI
{                            // Start the program
    float a,r;               // declare a,r as float
    printf("nEnter r: ");   // Prompt user to input the value of r
    scanf("%f",&r);          // Read the user input
    a = PI * r * r;          // Compute area
    printf("n%f %f",r,a);   // Print radius and area
}                            // Stop the program

If you adhere to these 4 steps in your early days of learning programming, I can assure you that you will make a good programmer.


comments powered by Disqus

Download Mobile App for Android

Web Service Offers

Website Starter - 5 Pages

Get started with your own website at most affordable cost.

15,000 5,000 (66.67% off)

Ecommerce Starter

Start selling your products online. Scale up as your business grows.

35,000 25,000 (28.57% off)

Looking to build a website?
Launch a 5 page website in 1 day at only Rs.499/year. Hosting included.

About the Author

Rajeev Kumar
CEO, Computer Solutions
Jamshedpur, India

Rajeev Kumar is the primary author of How2Lab. He is a B.Tech. from IIT Kanpur with several years of experience in IT education and Software development. He has taught a wide spectrum of people including fresh young talents, students of XLRI, industry professionals, and govt. officials.

Rajeev has founded Computer Solutions & WebServicesWorldwide.com, and has hands-on experience of building variety of web applications and portals, that include - SAAS based ERP & e-commerce systems, independent B2B, B2C, Matrimonial & Job portals, and many more.

Copyright © How2Lab.com. All rights reserved.

Refer a friend | Sitemap | Disclaimer | Privacy Policy