Introduction to Computer Programming

Introduction to Computer Programming

This is an introductory notes on computer programming using C programming language. Before getting into programming, we have to understand a few terms and problem solving methods well. Some of these important terms are:

1. Computer

Generally, a computer is a machine and is often defined as a machine that takes some input, processes it and gives some output as a result.

 

2. Hardware

This refers to the physical components of the computer system. For example Monitors, printers, etc.

 

3. Software

This refers to the computer readable instructions that direct a computer’s processor to perform some specific tasks. Example: Text-editors, video editors, etc.

 

4. Input Devices

These devices are peripherals that are responsible for feeding data to the computer. Some examples of this devices are a keyboard, mouse, DVD readers, etc.

 

5. Output Devices

These are set of peripherals responsible for storing data into memory or supplying it to the users. Some of these devices are a hard disk, monitors, printers, etc.

 

6. Data

Any raw facts and statistics collected for performing some computational operations.

 

7. Bit, Byte, Kilobyte, Megabyte, Gigabytes

Like distances are measured in meters or yards data are being measured in the units like bits and bytes. A bit is the smallest unit of data (and can have the value of 0 / 1 or Boolean value of true or false). Their order and representations are shown below:

Unit Representation
1 bit A single digit, either 1 or 0.
4 bits 1 nibble
8 bits 1 byte
210 or 1024 Bytes 1 KB (kilobyte )
210 or 1024 KB 1 MB (megabyte)
210 or 1024 MB 1 GB (gigabyte)
210 or 1024 GB 1 TB (terabytes)

8. Program

A program is a set of instructions for a computer to perform a specific task.

 

9. Levels of Programming Languages

a. Machine Languages

i. It is a language closer to natural languages.
ii. E.g.: FORTRAN, Pascal, C++, etc.

b. Low-level Languages

i. It is a language which is a Machine-oriented.
ii. E.g.: Assembly Language, Machine Language.

c. High-level Languages

i. Language that can be directly understood and obeyed by a machine (computes without conversion/translation).

 

10. Text Editors

These refer to that computer software that allows a programmer to write code. Examples of some of the text editors are Notepad++, Sublime Text.

 

11. Compiler

It is a computer program/set of computer programs that transforms source code written in a programming language into another computer language. The source code is converted to object code to create an executable program.

 

12. Assembler

A computer program that translates from assembly language to machine language/object file.

 

13. Interpreter

It is a computer program that executes i.e. performs instructions written in a programming language.

 

14. Algorithm

a. Technically, it is often defined as the

A well-defined procedure that consists a finite sequence of precise steps for solving computational problems.

b. All the algorithms are expected to satisfy the following criteria:

i. Input: Zero or more quantity are externally supplied
ii. Output: At least one quantity must be produced
iii. Definiteness: Each instruction must be clear and unambiguous
iv. Finiteness: The algorithm must be terminated after a finite number of steps

 

15. Flowchart

Now we understand what an algorithm is. It can be expressed in various ways. One of them is a representation through flowcharts. Basically, flowcharts are a graphical representation of finite steps involved in solving computational problems. There is a number of symbols used to represent different stages in problem-solving (not all the standards may use the same symbols). In design analysis a couple of symbols are sufficient. For example, a rectangle would represent a process and a diamond would represent a decision-making point. Some of the other symbols are shown in the figure given below:

Flowchart symbols by bhutanio.com
Flowchart symbols

General tips to remember while building flowcharts:

a. All the symbols should be connected by flow lines.
b. There should both the terminals – a start at the top and an end at the bottom generally.
c. The decision points have two exit points, generally Boolean 0 or 1 (meaning true on one side and false on the other).
d. Use the connectors while breaking the pages – for instances, off-page reference connector if the flowchart doesn’t fit in a single page and on-page reference connector if you want to continue flowchart on the same page’s on the top after reaching to the bottom on a side.
e. Subroutines/functions and interrupt programs can have their own and independent flowcharts.

16. Pseudocode

It is another way to express an algorithm. It can be defined as an expression of algorithms in a way that it can be easily transformed into programs but without using any specific programming language syntax. Thus, pseudo codes can be transformed into programs of any programming language.

Pseudo codes and their styles may vary from author to author but generally they are in a form are similar to syntaxes popular programming languages like C and Pascal. They are compact and does not tend to run over many pages. Often they can be easily modified, unlike flowcharts. Therefore, many computer science textbooks use pseudo codes for expressing algorithms.

Some tips to remember while writing pseudo codes:

1. Statements should be precise, understandable and programming language independent.
2. Steps must be definite.
3. Each line should express distinct instructions.
4. Capitalize the keywords.
5. It should be easily transformable into programming languages.

Some of the keywords used to denote programming processes are:

1. Input: READ, GET, OBTAIN
2. Output: PRINT, DISPLAY, SHOW
3. Compute: COMPUTE, CALCULATE, DETERMINE
4. Initialize: SET, INITIALIZE
5. Add periodically: INCREMENT
6. Subtract periodically: DECREMENT

Example 1:
To understand it better let us look into an algorithm to check whether a number is even or odd. Assume the number is to be fed as input by the user.

Algorithm:

Step 1: Start
Step 2: Get the number, n
Step 3: Perform n%2
Step 4: if n%2 equals 0 the number is even else odd
Step 5: Stop

Pseudocode:

START
GET n
IF n%2==0
print “n is even”
ELSE
print “n is odd”
STOP

Flowchart:

Flowchart to check even or odd by bhutanio.com
Flowchart to check the number is even or odd

17. Data types

It is a very important term to understand what data types are. In the rest of your study or career in computer science, you are going to deal with data and these would have their own type. Data types define the types of variables or functions. Some of the important data types are mentioned below.

a. Integer types

The table below shows standard integer types and their sizes.

SR# Type Storage Size
1. signed Char 1 bye
2. Int 2 or 4 bytes
3. unsigned int 2 or 4 bytes
4. Short 2 bytes
5. unsigned short 2 bytes
6. Long 4 bytes
7 unsigned long 4 bytes

 

b. Floating point types

SR# Type Storage Size
1. float 4 bytes
2. double 8 bytes
3. Long double 10 bytes

%d bloggers like this: