1 of 29

Basics of Programming

Mrs Sangeeta Bhandari

PG Department of Computer Science & IT

HMV, Jalandhar

2 of 29

Contents

Computer Programming Languages

  • And Flowcharts
  • We will learn
        • Computer Programming Languages.
        • Non-computational languages
        • Machine language
          • Example
        • Assembly language
          • Example
        • High level language
          • Examples.

3 of 29

Programming

  • Computer programming is the process of performing a particular computation, usually by designing and building an executable computer program. Programming involves tasks such as analysis, generating algorithms, profiling algorithms' accuracy and resource consumption, and the implementation of algorithms.

4 of 29

Flowchart

  • A flowchart is a diagram that depicts a process, system or computer algorithm. They are widely used in multiple fields to document, study, plan, improve and communicate often complex processes in clear, easy-to-understand diagrams.

5 of 29

Flowchart Symbols

  • Flowcharts use special shapes to represent different types of actions or steps in a process. Lines and arrows show the sequence of the steps, and the relationships among them. These are known as flowchart symbols.

6 of 29

Flowchart Symbols

7 of 29

Flow chart of the while loop :

8 of 29

Flow chart of the for loop:

9 of 29

The flow chart of the if statement:

10 of 29

The flow chart of the if…else statement:

11 of 29

The flow chart of the switch statement:

12 of 29

Flowchart for finding the sum of first five natural numbers ( i.e. 1,2,3,4,5):

13 of 29

Flowchart (Example):

Flowchart to find the sum of first 50 natural numbers.

14 of 29

Start

Read A, B

Is A > B

Print A

Print B

End

Yes

No

Flow Chart to find largest of two numbers:

15 of 29

Flowchart to find the largest of three numbers A,B, and C:

NO

16 of 29

LIMITATIONS OF USING FLOWCHARTS:

  • Complex logic: Sometimes, the program logic is quite complicated. In that case, flowchart becomes complex and clumsy.

  • Alterations and Modifications: If alterations are required the flowchart may require re-drawing completely.

  • Reproduction: As the flowchart symbols cannot be typed, reproduction of flowchart becomes a problem.

17 of 29

Flowchart (Exercise):

  1. Draw a flowchart to depict all steps that you do reach your college.

  • Draw Flowchart for Linear search.

18 of 29

Computer Programming Languages:

  • A programming language is an artificial language that can be used to control the behavior of a machine, particularly a computer

  • Programming languages, like human languages, are defined through the use of syntactic and semantic rules, to determine structure and meaning respectively.

19 of 29

Computer Programming Languages (Contd…):

  • Programming languages are used to facilitate communication about the task of organizing and manipulating information, and to express algorithms precisely.

  • For 50 years, computer programmers have been writing code. New technologies continue to emerge, develop, and mature at a rapid pace. Now there are more than 2,500 documented programming languages!

20 of 29

Non-computational languages:

  • Non-computational languages, such as markup languages like HTML or formal grammars like BNF, are usually not considered programming languages.

  • Often a programming language is embedded in the non-computational language.

21 of 29

Machine language:

  • It is the lowest-level programming language.
  • Machine languages are the only languages understood by computers.

22 of 29

Machine language:

  • While easily understood by computers, machine languages are almost impossible for humans to use because they consist entirely of numbers.

For example, an x86/IA-32 processor can execute the following binary instruction as expressed in machine language:

Binary: 10110000 01100001 (Hexadecimal: 0xb061)

23 of 29

Assembly Level Language:

  • An assembly language is a low-level language for programming computers.

  • The word "low" does not imply that the language is inferior to high-level programming languages but rather refers to the small or nonexistent amount of abstraction between the language and machine language, because of this, low-level languages are sometimes described as being "close to the hardware."

  • It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture.

24 of 29

Assembly Level Language

  • A utility program called an assembler, is used to translate assembly language statements into the target computer's machine code.
  • The assembler performs a more or less isomorphic translation (a one-to-one mapping) from mnemonic statements into machine instructions and data.

Example: Assembly language representation is easier to remember (more mnemonic)

mov al, 061h

This instruction means:

Move the hexadecimal value 61 (97 decimal) into the processor register named "al".

The mnemonic "mov" is an operation code or opcode, A comma-separated list of arguments or parameters follows the opcode;

25 of 29

Example (Adds 2 numbers):

name "add"

mov al, 5 ; bin=00000101b

mov bl, 10 ; hex=0ah or bin=00001010b

add bl, al ; 5 + 10 = 15 (decimal) or hex=0fh or

bin=00001111b

26 of 29

High-level language:

  • High-level languages are relatively easy to learn because the instructions bear a close resemblance to everyday language, and because the programmer does not require a detailed knowledge of the internal workings of the computer.

  • Each instruction in a high-level language is equivalent to several machine-code instructions, therefore it is more compact than equivalent low-level programs.

  • High-level languages are used to solve problems and are often described as problem-oriented languages

27 of 29

High-level language

Examples of HLL:

  • BASIC was designed to be easily learnt by first-time programmers;
  • COBOL is used to write programs solving business problems;
  • FORTRAN is used for programs solving scientific and mathematical problems.
  • With the increasing popularity of windows-based systems, the next generation of programming languages was designed to facilitate the development of GUI interfaces;

for example, Visual Basic wraps the BASIC language in a graphical programming environment.

  • Support for object-oriented programming has also become more common, for example in C++ and Java.

28 of 29

Example (C program to add 2 numbers):

#include<stdio.h> //header files

Void main()

{

int a, b, c; // declaration of 3 variables

printf(“Enter two numbers:\n”);

Scanf(“%d”, &a); // read 1st number

Scanf(“%d”, &b); // read 2nd number

c=a+b; // compute the sum

printf(“Sum of 2 numbers is %d”, c); //print sum

}

29 of 29

  • ThankYou !!!