Академический Документы
Профессиональный Документы
Культура Документы
Ashim Lamichhane 1
Intro
• Number of problems in our daily life.
• Suppose we have to calculate Simple Interest.
• Suppose we have to prepare a mark sheet.
Ashim Lamichhane 2
• A software is a set of programs written to
solve a particular problem
Ashim Lamichhane 3
Never Ever Forget
• Just writing code is not sufficient to solve a
problem.
Ashim Lamichhane 4
Stages while solving a problem using
computer
1. Problem Analysis
2. Algorithm Development
3. Flowcharting
4. Coding
5. Compilation and Execution
6. Debugging and Testing
7. Documentation
Ashim Lamichhane 5
Problem Analysis
Algorithm Development
Flowcharting
Program Coding
Documentation
Ashim Lamichhane 7
Algorithm Development
• Step By Step description of the method to
solve a problem.
Step 1: Start
Step 3: Add two numbers x and y; store the value in variable sum
Ashim Lamichhane 9
An algorithm to find sum of two numbers:
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum Step 6: Stop
Ashim Lamichhane 10
An algorithm to find largest of three different
numbers:
Ashim Lamichhane 11
Three features of Algorithm
• Sequence
– Each step in the algorithm in executed in specified order. If not
algorithm will fail.
• Decision
– We have to make decision to do something.
– If the outcome of the decision is true, one thing is done otherwise
other.
• If condition then process1
OR
• If condition
then process1
Else process2
• Repetition
– For example
Repeat
Fill Water in the kettle
Until Kettle is full
Ashim Lamichhane 12
Flowcharting
• Graphical representation of an algorithm using standard
symbols.
Ashim Lamichhane 13
Advantages of Flowcharts
• Communication
– Quickly provide logic, ideas and descriptions of algorithms.
• Effective Analysis
– Clear overview of the entire problem.
• Proper Documentation
– Documents the steps followed in an algorithm.
– Helps us understand its logic in future.
• Efficient Coding
– More ease with comprehensive flowchart as a guide
• Easy in debugging and program maintenance
– Debugging and maintenance of operating program
Ashim Lamichhane 14
Flowchart Symbols
Ashim Lamichhane 15
Things to consider
• There should be start and stop to the flowchart.
Ashim Lamichhane 16
Write an algorithm and draw flowchart for finding the
sum of any two numbers.
Algorithm
-------------
Step1: Start
Step2: Display “Enter two numbers”.
Step3: Read A and B
Step4: C= A+B
Step5: Display “C as sum of two numbers”
Step6: Stop
Ashim Lamichhane 17
Flowchart
START Start
Read two
Numbers, A and B
Input
C=A+B Processing
END End
Ashim Lamichhane 18
Some questions for Assignment
Ashim Lamichhane 20
Coding
• The process of transforming the program logic design into
computer language format.
Ashim Lamichhane 22
Execution
• Once the compilation is completed then the program
is linked with other object programs needed for
execution, there by resulting in a binary program and
then the program is loaded in the memory for the
purpose of execution and finally it is executed.
Ashim Lamichhane 23
Debugging and Testing
• Debugging is the discovery and correction of
programming errors.
Ashim Lamichhane 24
Debugging and Testing
• Testing ensures that program performs correctly the
required task.
Ashim Lamichhane 27
Computer Program
and
Programming Language
Ashim Lamichhane 28
Computer Program
• Set of instructions that causes to behave in predetermined
manner.
Ashim Lamichhane 29
Types or levels of Programming
Languages
• High Level
• Low-level
– Machine Level
– Assembly Level
Ashim Lamichhane 30
Low Level Language
• Statement or instruction is directly translated
into a single machine code.
Ashim Lamichhane 31
Machine-level Language
• Language that a computer actually understands.
• 1’s and 0’s.
• Is a sequence of instructions written in the form of
binary numbers consisting of 1’s and 0’s
• It executes fast as computer don’t need any
translation.
Ashim Lamichhane 32
• To add two number in machine language:
11 10111001 110
3 machine code for addition (say) 6
Ashim Lamichhane 33
Machine Level Language
ADVANTAGE DISADVANTAGE
Computer directly understands machine Difficult to use
instructions
Directly starts executing Machine dependent
Takes less execution time Difficult to Debug and modify
Ashim Lamichhane 34
Assembly Language
• Symbolic representation(mnemonics) of machine code.
11 ADD 110
– Suppose ADD is mnemonic for addition
Ashim Lamichhane 35
Some examples of instructions for
assembly languages are as follows:
CODE Meaning
ADD Addition
SUB Subtraction
INR Increase
DCR Decrease
CMP Compare
Ashim Lamichhane 36
Assembly language
Advantage Disadvantage
More convenient than machine language Hard to remember Mnemonics
Symbolic instructions Machine dependent
Improved readability Less efficient than machine language
Need fewer codes than high level
language
Embedded systems and device
programming
Ashim Lamichhane 37
High Level Language
Ashim Lamichhane 38
High Level Language
Advantages Disadvantages
Easy to use More execution time
Portability Needs own translator
Easy Debugging
Easy and Fast Development of software
Ashim Lamichhane 39
Compiler
• A high level source program must be translated into a form machine
can understand. This done by software called the compiler.
Ashim Lamichhane 40
Interpreter
• Like compiler, it is also a translator which translates high level
to machine level language.
Ashim Lamichhane 41
Difference between compiler and interpreter
Compiler Interpreter
Compiler scans the entire program before Interpreter translates and executes the
translating it into machine code program line by line
Syntax errors are found only after the Syntax errors can be trapped after
compilation of complete programs translations of every line
It takes large amount of time to analyze It takes less amount of time to analyze the
the source code but the overall execution source code but the overall execution
time is comparatively faster. time is slower.
Ashim Lamichhane 42
Overview to C Programming
Ashim Lamichhane 43
• We can assume C as middle level language
• This doesn’t mean C is less power full or harder to use or less developed.
Ashim Lamichhane 44
History of C programming language
• C is a programming language which was born at “AT & T’s Bell
Laboratory” of USA in 1972.
• It’s use quickly spread beyond Bell Labs in the late 70’s
Ashim Lamichhane 45
Why use C?
• Robust Language
• Efficient and fast
• Highly portable
• Structured Language
• Extendibility
• Middle level language
• Rich system library
Ashim Lamichhane 47
Executing a C Program
Ashim Lamichhane 48
Basic Structure of C Program
Ashim Lamichhane 49
1. Documentation Section
• Sets of comment line giving the name of
program, the author, algorithms, methods
used and other details.
• Acts as a communication between members
of the development team.
• Acts as user manual.
• Ex
– /* This program adds two numbers */
– /*…. */ denotes comments in C
Ashim Lamichhane 50
2. Link Section
- Provides Instructions to the compiler to link
functions with program from the system library.
#include<stdio.h>
- Links input/output functions like printf() and
scanf() with the program
Ashim Lamichhane 51
3. Definition Section
- In this section all symbolic constants are
defined.
- Ex.
- #define PI 3.1416
- #define FORMULA 3*x*x*x+2*x*x
Ashim Lamichhane 52
4. Global Declaration Section
- The variables which are used in more than
one functions or blocks are called global
variables.
Ashim Lamichhane 53
5. main() Function Section
- Every C program starts with a main() function.
- Declaration part and executable part
Ashim Lamichhane 54
6. Subprogram Section
- This section contains all the user-defined
functions that are called in the main function.
Ashim Lamichhane 55
Note
• For Assignments And Lecture Slides
https://github.com/ashim888/csit-c
http://www.ashimlamichhane.com.np/
Ashim Lamichhane 56