Programming Concepts
Programming Concepts
&
Logic
Introduction to programming languages
As we know, to communicate with a person, we need a specific language, similarly
to communicate with computers, programmers also need a language is called
Programming language.
Language is a mode of communication that is used to share ideas, opinions with
each other.
A programming language is a computer language that is used by programmers
(developers) to communicate with computers. It is a set of instructions written in
any specific language ( C, C++, Java, Python) to perform a specific task.
Continue..
A computer is a sequence of instruction written using a computer
programming language to perform a specified task by the computer.
Characteristics of Good Program
Portability:- Portability refers to an application to run on a different platform,
which or without minimum changes. If the program is developed for a particular
platform then the like Span of the program is severely affected.
Generality:- Apart from the flexibility of the program should also be general.
By Generality, we mean that, if a program is developed for a particular task,
then it should also be used for all similar tasks of the same domain.
Types of programming language
Machine Level language
Assembly Language
High Level Language
Machine Level language
Machine language is the lowest level of programming language that directly corresponds
to the instructions executed by a computer's hardware.
Low-Level language is the only language which can be understood by the computer. Low-
level language is also known as Machine Language.
The machine language contains only two symbols 1 & 0. All the instructions of machine
language are written in the form of binary numbers 1's & 0's. A computer can directly
understand the machine language.
High-Level Machine
Language Language
101011010
( A + B ) /2 Translator 00101010
111000110
Source Code Object Code
Assembly Language
Middle-level language is a computer language in which the instructions are created using
symbols such as letters, digits and special characters. Assembly language is an example of
middle-level language. In assembly language, we use predefined words called mnemonics.
Binary code instructions in low-level language are replaced with mnemonics and operands
in middle-level language. But the computer cannot understand mnemonics, so we use a
translator called Assembler to translate mnemonics into machine language.
High-Level Machine
Language Language
101011010
( A + B ) /2 Translator
00101010
111000110
Source Code Object Code
High Level Language
High-level language is a computer language which can be understood by the users. The high-
level language is very similar to human languages and has a set of grammar rules that are
used to make instructions more easily.
Every high-level language has a set of predefined words known as Keywords and a set of
rules known as Syntax to create instructions.
High-Level Machine
Language Language
101011010
( A + B ) /2 Translator 00101010
111000110
Source Code Object Code
Types of High level Language
Procedural oriented language (3GL)
Problem oriented language (4GL)
Natural Language (5GL) / Artificial Intelligence Languages
Types of Translator
A language processor is a software component or a set of tools that performs
various tasks related to the processing of human languages. There are different
types of language processors, each serving a specific purpose. Here are a few key
types:
These errors are mainly occurred due to the mistakes while typing or do not follow the
syntax of the specified programming language.
Run-time error
Sometimes the errors exist during the execution-time even after the successful
compilation known as run-time errors.
When the program is running, and it is not able to perform the operation is the main
cause of the run-time error.
The division by zero is the common example of the run-time error.
These errors are very difficult to find, as the compiler does not point to these errors.
Linker error
Linker errors are mainly generated when the executable file of the program is not
created.
This can be happened either due to the wrong function prototyping or usage of the
wrong header file.
For example, the main.c file contains the sub() function whose declaration and
definition is done in some other file such as func.c.
Logical error
The logical error is an error that leads to an undesired output. These errors produce the
incorrect output, but they are error-free, known as logical errors.
These types of mistakes are mainly done by beginners. The occurrence of these errors
mainly depends upon the logical thinking of the developer.
If the programmers sound logically good, then there will be fewer chances of these errors.
Semantic error
Semantic errors are the errors that occurred when the statements are not understandable by
the compiler. The following can be the cases for the semantic error:
Use of a un-initialized variable.
int i;
i=i+2;
Type compatibility
int b = "javatpoint";
Errors in expressions
int a, b, c;
a+b = c;
Array index out of bound
int a[10];
a[10] = 34;
Note: In the above code, we use the statement a+b =c, which is incorrect as we cannot use the
two operands on the left-side.
Control Structures
Control structures in C programming are constructs that enable you to control the flow
of execution within your program. These structures allow you to make decisions,
repeat actions, and execute code based on certain conditions. The three main types of
control structures in C are:
Selection Structures (Conditional Statements)
if statement: Executes a block of code if a specified condition is true.
if-else statement: Executes one block of code if a specified condition is true and another
block of code if the condition is false.
nested if-else statement: Allows you to have multiple levels of conditional statements.
switch statement: Evaluates an expression and executes code based on different possible
values of the expression.
Iteration Structures (Loops)
while loop: Executes a block of code repeatedly as long as a specified condition is true.
do-while loop: Executes a block of code once, and then repeatedly executes the block
as long as a specified condition is true.
for loop: Executes a block of code repeatedly for a fixed number of times.
Select /Jump Statements
break statement: Terminates the current loop or switch statement and transfers
control to the statement immediately following the terminated statement.
continue statement: Skips the current iteration of a loop and continues with the next
iteration.
Go to statement: Transfers control to a labeled statement within the same function.
Program Design Tools
Algorithm Flowchart Pseudo Code
Algorithm
An algorithm is a step-by-step procedure or set of rules that must be followed to
perform a specific task or solve a particular problem.
In the context of computer science and mathematics, an algorithm is a well-defined,
finite sequence of instructions or computational steps that transforms input data into
output.
A flowchart is a type of diagram that represents a workflow or process. A flowchart can also
be defined as a diagrammatic representation of an algorithm, a step-by-step approach to
solving a task.
Flowchart Notation
Computer Codes
Absolute Binary BCD ASCII
EBCDIC Unicode
Absolute Binary
"Absolute binary" is not a standard term in computing. However, it's possible that you're
referring to binary representation without any encoding scheme or modification, where each
binary digit (bit) represents the exact value of a number in base-2.
Absolute binary is the simplest form of binary representation, where each bit directly
corresponds to the value of a power of 2 without any encoding, padding, or modification.
Binary-Coded Decimal(BCD)
BCD, or Binary-Coded Decimal, is a way of representing decimal numbers using binary
notation. In BCD, each decimal digit is represented by a 4-bit binary code. This allows for
efficient storage and manipulation of decimal numbers in digital systems.
In standard binary representation, each decimal digit (0-9) is represented using 4 binary
bits (0000 to 1001).
In BCD, each decimal digit is also represented using 4 bits, but the range is limited to 0000
to 1001 to only represent the decimal digits (0-9).
For example, the decimal number 123 in BCD would be represented as follows:
1 is represented as 0001
2 is represented as 0010
ASCII
ASCII, which stands for American Standard Code for Information Interchange, is a character
encoding standard that assigns numeric codes to represent characters in computers.
It was developed in the early days of computing to provide a standardized way for computers
to represent and exchange text data.
For example, here are some ASCII codes and their corresponding characters:
ASCII code 65 represents the uppercase letter 'A'.
ASCII code 97 represents the lowercase letter 'a'.
ASCII code 32 represents the space character.
EBCDIC
EBCDIC, which stands for Extended Binary Coded Decimal
Interchange Code, is another character encoding standard used
in computing, particularly in IBM mainframe systems.
EBCDIC was designed to support punched cards, which were
commonly used for data entry and storage in early computing
systems
Despite its declining use, EBCDIC is still used in some legacy
systems, where mainframe systems are still in use and
compatibility with older data formats is required.
Each character is represented by an 8-bit binary number (0 or 1),
providing a total of 256 possible characters.
Unicode
Unicode is a character encoding standard that aims to represent every character from every
language and symbol system in the world.
Unicode maintains backward compatibility with older character encoding standards like
ASCII.
Unicode includes characters from virtually all writing systems and symbol sets used
throughout the world, making it a comprehensive standard for text representation in
computing.
Homework
What is loop? List its types and explain each.
What is an algorithm? Explain need of an algorithm.
Write an algorithm to find average age of a group of 10 players.
Explain use of flowchart.
Draw a flowchart to find the sum of first 100 natural numbers.
Draw a flowchart to know a number is even or odd.
Thank you !!!