ITskills Unit 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Unit – 1

Introduction to basics of coding


What is Computer Programming?

Computer Programming is a step by step process of designing and developing various sets of computer
programs to accomplish a specific computing outcome. The process comprises several tasks like analysis,
coding, algorithm generation, checking accuracy and resource consumption of algorithms, etc.
A computer program is a sequence of instructions written using a Computer Programming Language to
perform a specified task by the computer.
The two important terms that we have used in the above definition are −

● Sequence of instructions
● Computer Programming Language
If you understand what a computer program is, then we will say: the act of writing computer programs is called
computer programming.
There are hundreds of programming languages, which can be used to write computer programs and
following are a few of them −

● Java
●C
● C++
● Python
● PHP
● Perl
● Ruby

Basics of programming

Just like human languages, programming languages also follow grammar called syntax. There are certain basic
program code elements which are common for all the programming languages.
Most important basic elements for programming languages are:

● Programming Environment
● Data Types
● Variables
● Keywords
● Logical and Arithmetical Operators
● If else conditions
● Loops
● Numbers, Characters and Arrays
● Functions
● Input and Output Operations
Algorithm

Algorithm is a step-by-step procedure to resolve any problem. An algorithm is an effective method expressed as
a finite set of well-defined instructions.

Algorithms are generally created independent of underlying languages, i.e. an algorithm can be implemented in
more than one programming language. From the data structure point of view, following are some important
categories of algorithms −

● Search − Algorithm to search an item in a data structure.


● Sort − Algorithm to sort items in a certain order.
● Insert − Algorithm to insert item in a data structure.
● Update − Algorithm to update an existing item in a data structure.
● Delete − Algorithm to delete an existing item from a data structure.
Characteristics of an Algorithm
Not all procedures can be called an algorithm. An algorithm should have the following characteristics:
● Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or phases), and their
inputs/outputs should be clear and must lead to only one meaning.
● Input − An algorithm should have 0 or more well-defined inputs.
● Output − An algorithm should have 1 or more well-defined outputs, and should match the desired output.
● Finiteness − Algorithms must terminate after a finite number of steps.
● Feasibility − Should be feasible with the available resources.
● Independent− An algorithm should have step-by-step directions, which should be independent of any
programming code.
We design an algorithm to get a solution of a given problem. A problem can be solved in more than one ways.

Hence, many solution algorithms can be derived for a given problem. The next step is to analyze those
proposed solution algorithms and implement the best suitable solution.
Example: Design an algorithm to add two numbers and display the result.

Alternatively, the algorithm can be written as –

Flowchart
Flowchart is a diagrammatic representation of sequence of logical steps of a program.
Flowchart is a graphical representation of an algorithm. Programmers often use it as a program-planning tool to
solve a problem. It makes use of symbols which are connected among them to indicate the flow of information
and processing.
The process of drawing a flowchart for an algorithm is known as “flowcharting”. Flowcharts use simple
geometric shapes to depict processes and arrows to show relationships and process/data flow.

Guidelines for Developing Flowcharts


These are some points to keep in mind while developing a flowchart −
● Flowchart can have only one start and one stop symbol
● On-page connectors are referenced using numbers
● Off-page connectors are referenced using alphabets
● General flow of processes is top to bottom or left to right
● Arrows should not cross each other

Flowchart Symbols
Here is a chart for some of the common symbols used in drawing flowcharts.

Examples of Algorithm and flowchart

1.To Calculate sum of two numbers


Algorithm :sum of two numbers
input:any two numbers
output:sum of 2 numbers
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values for num1, num2.
Step 4: Add num1 and num2 and assign the result to a variable sum.
Step 5: Display sum
Step 6: Stop
Flowchart:
2. To Calculate subtraction of two numbers

Algorithm : subtraction of two numbers


input: any two numbers
output: subtraction of 2 numbers
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values for num1, num2.
Step 4: subtract num1 and num2 and assign the result to a variable
sum. Step 5: Display sum
Step 6: Stop
3.To print largest of three numbers
Algorithm: Largest of 3 numbers
Input: any 3 integer values
Output: largest of 3 numbers

1. Start
2. Input A,B,C
3. If (A>B) and (A>C) then print “A is greater”.
Else if (B>A) and (B>C) then print “B is greater”.
Else print “C is greater”.
4. Stop

Flowchart:

4 .To print largest of three numbers


Algorithm: Smallest of 3 numbers
Input: any 3 integer values
Output: largest of 3 numbers

1. Start
2. Read a,b,c
3. If (a<b) and (a<c) then print “a is smaller”.
Else if (b<a) and (b<c) then print “b is smaller”.
Else print “c is smaller”.
4. Stop

Flowchart:

5.To Calculate and print sum of ‘N’ numbers


Algorithm:

Step 1 : Start
Step 2 : Assign sum=0 and i=0
Step 3 : Read limit of number , n
Step 4 : Repeat steps 5 to 6 until i=n reached
Step 5 : Compute sum=sum+i
Step 6 : Compute i=i+1
Step 7 : Print sum
Step 8 : Stop

Flowchart:

You might also like