SlideShare a Scribd company logo
Unit 1. Problem Solving with
Computer
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.
• A computer is a DUMB machine.
• A computer cannot do anything alone without
software i.e. Program
Ashim Lamichhane 2
• A software is a set of programs written to
solve a particular problem
• Software is a set of instructions on the basis of
which computer gives output/result.
• If the instructions are not correct, the
computer gives wrong result.
Ashim Lamichhane 3
Never Ever Forget
• Just writing code is not sufficient to solve a
problem.
• Program must be planned before coding in
any computer language available.
• There are many activities to be done before
and after writing code.
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
Fig. Steps in problem solving
Ashim Lamichhane 6
Algorithm Development
Flowcharting
Documentation
Debugging and Testing
Compilation and Execution
Program Coding
Problem Analysis
Problem Analysis
• Process of becoming familiar with the problem.
• We need to analyze and understand it well before
solving.
• The user’s requirements cannot be fulfilled without clear
understanding of his/her problem in depth.
• Inadequate identification of problem may cause
program less useful and insufficient.
• Example: Banking Solution, Hospital Medical Study
Ashim Lamichhane 7
Algorithm Development
• Step By Step description of the method to
solve a problem.
• Effective procedure for solving a problem in
finite number of steps.
• Developing an algorithm is a step of program
design.
Ashim Lamichhane 8
An algorithm to find sum of two numbers:
Step 1: Start
Step 2: Assume two numbers x and y and a variable sum=0
Step 3: Add two numbers x and y; store the value in variable sum
Step 4: If you want to try again with different numbers
then goto step 2
else
goto step 5
Step 5: END
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.
• Includes a set of various standard shaped boxes that are
interconnected by flow lines.
• Flow lines have arrows(direction of flow).
• Activities are written within boxes in English.
• Communicates between programmers and business
persons.
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.
• Only one flow line should emerge from a
process symbol.
• Only one flow line should enter a decision
symbol, but two or three flow lines can leave
the decision symbol.
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
Ashim Lamichhane 18
START
END
Read two
Numbers, A and B
Display C as Sum of A and B
C = A + B
Input
Start
Output
End
Processing
Some questions for Assignment
• Write an algorithm and draw flowchart to
determine a number whether it is positive or
negative.
• Write an algorithm and draw flowchart to test
a number for even or odd.
• Write an algorithm and draw flowchart to find
the largest number among three numbers.
Ashim Lamichhane 19
• Read N numbers from user and display sum of
all entered numbers.
• For finding the sum of the series 1+2+3+4+…
up to N terms
• For calculating the factorial of a given number
N.
Ashim Lamichhane 20
Coding
• The process of transforming the program logic design into
computer language format.
• An act of transforming operations in each box of the flowchart
in terms of the statement of the program.
• The code written using programming language is also known
as source code.
• Coding isn’t the only task to be done to solve a problem using
computer.
• Anyone can code. TRUST ME!!
Ashim Lamichhane 21
Compilation
• Process of changing high level language into machine level
language.
• It is done by special software, COMPILER
• The compilation process tests the program whether it
contains syntax errors or not.
• If syntax errors are present, compiler can not compile the
code.
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.
• The program may ask user for inputs and generates
outputs after processing the inputs.
Ashim Lamichhane 23
Debugging and Testing
• Debugging is the discovery and correction of
programming errors.
• Some errors may remain in the program because the
designer/programmer might have never thought
about a particular case.
• When error appears debugging is necessary.
Ashim Lamichhane 24
Debugging and Testing
• Testing ensures that program performs correctly the
required task.
• Verification ensures that program does what the
programmer intends to do.
• Validation ensures that the program produces the
correct results for a set of test data.
• Test data are supplied to the program and output is
observed.
• Expected output = Error free
Ashim Lamichhane 25
Program Documentation
• Helps to those who use, maintain and extend the
program in future.
• A program may be difficult to understand even to
programmer who wrote the code after some
days.
• Properly documented program is necessary
which will be useful and efficient in debugging,
testing, maintenance and redesign process.
Ashim Lamichhane 26
Two types of documentations
1. Programmer’s Documentation (Technical
Documentation)
• Maintain, redesign and upgrade
• Logic, DFD, E-R, algorithm and flowchart
2. User Documentation (User Manual)
• Support to the user of the program
• Instructions for installation of the program
Ashim Lamichhane 27
Computer Program
and
Programming Language
Ashim Lamichhane 28
Computer Program
• Set of instructions that causes to behave in predetermined
manner.
• To instruct a computer to perform a certain job, we need
languages, but not English or Nepali(!!!FOR NOW!!!).
• We need languages understood by the computer.
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.
• It is machine dependent, i.e. A particular low-
level language works only for a certain
machine.
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
• It is difficult to remember different instructions for
programming.
Ashim Lamichhane 33
Machine Level Language
ADVANTAGE DISADVANTAGE
Computer directly understands machine
instructions
Difficult to use
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.
• Close to machine code but the computer cannot understand
• Must be translated into machine code by a separate program
called an assembler.
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
It is relatively easy for writing programs in assembly
languages, but is slow in execution as it has to be
converted into machine language before execution.
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
• User friendly, Similar to natural languages
• Platform independent
• Easy to write or remember
• Easy to learn and work
• While execution: translated into assembly language then to
machine language.
• Slow in execution but is efficient for developing programs.
• Ex: C, C++, Python, Java etc.
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.
• Source code => Machine language code(Object code)
• During the process of translation, the compiler reads the source
programs statement-wise and checks for syntax errors.
• In case of any error, the computer generates message about the
error.
• Ex: C, C++, Java, FORTRAN, pascal etc.
Ashim Lamichhane 40
Interpreter
• Like compiler, it is also a translator which translates high level
to machine level language.
• Translates and executes the program line by line.
• Each line is checked for syntax error and then converted to
the equivalent machine code.
• Ex. QBASIC, PERL, PHP, ASP, PYTHON, RUBY
Ashim Lamichhane 41
Difference between compiler and interpreter
Compiler Interpreter
Compiler scans the entire program before
translating it into machine code
Interpreter translates and executes the
program line by line
Syntax errors are found only after the
compilation of complete programs
Syntax errors can be trapped after
translations of every line
It takes large amount of time to analyze
the source code but the overall execution
time is comparatively faster.
It takes less amount of time to analyze the
source code but the overall execution
time is slower.
Generates intermediate object code
which further requires linking, hence
requires more memory.
No intermediate object code is generated,
hence are memory efficient.
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.
• Instead C combines the advantages of high level language with the
functionalism of assembly language.
• Like high level, C provides block structures, stand-alone functions and
small amount of data typing.
• Like assembly language, it allows manipulations of bits, bytes, pointers
and it is mostly used in system programming.
• Combination of two aspects.
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.
• C was written by Dennis Ritchie, that’s why he is also called as
father of C programming language.
• C language was created for a specific purpose i.e. designing the
UNIX operating system (which is currently base of many UNIX based
OS).
• From the beginning, C was intended to be useful to allow busy
programmers to get things done because C is such a powerful,
dominant and supple language.
• 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.
- This section also declares all the user-defined
functions.
Ashim Lamichhane 53
5. main() Function Section
- Every C program starts with a main() function.
- Declaration part and executable part
- Declaration part declares all the variables used in
the execution part.
- int n1;
- int n2=5;
- Execution part has executable operations like:
- n1= n1 +1;
- n2=n1*5
Ashim Lamichhane 54
6. Subprogram Section
- This section contains all the user-defined
functions that are called in the main function.
- All the sections except the main function
section may be absent when they are not
required.
Ashim Lamichhane 55
Note
• For Assignments And Lecture Slides
https://github.com/ashim888/csit-c
http://www.ashimlamichhane.com.np/
Ashim Lamichhane 56

More Related Content

What's hot

Compilers
CompilersCompilers
Compilers
Bense Tony
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming conceptssalmankhan570
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
Rabin BK
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming ConceptsJussi Pohjolainen
 
Programming in c
Programming in cProgramming in c
Programming in c
indra Kishor
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
Tanzeela_Hussain
 
Problem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CProblem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to C
Prabu U
 
Computer organisation -morris mano
Computer organisation  -morris manoComputer organisation  -morris mano
Computer organisation -morris mano
vishnu murthy
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
shashidharPapishetty
 
Pseudocode
PseudocodePseudocode
Pseudocode
Harsha Madushanka
 
Data types in C
Data types in CData types in C
Data types in C
Tarun Sharma
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
Iffat Anjum
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
Syed Zaid Irshad
 
Introduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- PythonIntroduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- Python
PriyankaC44
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
Akhil Kaushik
 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
Sanjit Shaw
 
Theory of Computation
Theory of ComputationTheory of Computation
Theory of Computation
Shiraz316
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2
REHAN IJAZ
 
Algorithm Design & Implementation
Algorithm Design & ImplementationAlgorithm Design & Implementation
Algorithm Design & Implementation
Gaditek
 

What's hot (20)

Compilers
CompilersCompilers
Compilers
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming Concepts
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Problem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CProblem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to C
 
Computer organisation -morris mano
Computer organisation  -morris manoComputer organisation  -morris mano
Computer organisation -morris mano
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
Data types in C
Data types in CData types in C
Data types in C
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
 
Introduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- PythonIntroduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- Python
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Theory of Computation
Theory of ComputationTheory of Computation
Theory of Computation
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2
 
Algorithm Design & Implementation
Algorithm Design & ImplementationAlgorithm Design & Implementation
Algorithm Design & Implementation
 

Similar to Unit 1. Problem Solving with Computer

Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem sloving
Mani Kandan
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
MMRF2
 
Unit 1 program development cycle
Unit 1 program development cycleUnit 1 program development cycle
Unit 1 program development cycle
Dhana malar
 
C program execution and algorithm
C program execution and algorithm C program execution and algorithm
C program execution and algorithm
Kunal Pandhram
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
praveena p
 
INTRODUCTION TO C++, Chapter 1
INTRODUCTION TO C++, Chapter 1INTRODUCTION TO C++, Chapter 1
INTRODUCTION TO C++, Chapter 1
Mubarek Kurt
 
02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptx02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptx
arifaqazi2
 
01CHAP_1.PPT
01CHAP_1.PPT01CHAP_1.PPT
01CHAP_1.PPT
ManoRanjani30
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
MIT,Imphal
 
Programming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptxProgramming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptx
TeddyDaka
 
C++ programming program design including data structures
C++ programming program design including data structures C++ programming program design including data structures
C++ programming program design including data structures
Ahmad Idrees
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
Appili Vamsi Krishna
 
COM1407: Structured Program Development
COM1407: Structured Program Development COM1407: Structured Program Development
COM1407: Structured Program Development
Hemantha Kulathilake
 
Unit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and FlowchartUnit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and Flowchart
Bom Khati
 
PPS Unit-1.pdf
PPS Unit-1.pdfPPS Unit-1.pdf
PPS Unit-1.pdf
NenavathSurendhar
 
part_1 (1).ppt
part_1 (1).pptpart_1 (1).ppt
part_1 (1).ppt
lekha572836
 
Pseudo code.pptx
Pseudo code.pptxPseudo code.pptx
Pseudo code.pptx
Chaya64047
 
Fundamentals of programming with C++
Fundamentals of programming with C++Fundamentals of programming with C++
Fundamentals of programming with C++
Seble Nigussie
 
Algorithms and flow charts
Algorithms and flow chartsAlgorithms and flow charts
Algorithms and flow charts
Chinnu Edwin
 

Similar to Unit 1. Problem Solving with Computer (20)

Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem sloving
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
 
Unit 1 program development cycle
Unit 1 program development cycleUnit 1 program development cycle
Unit 1 program development cycle
 
C program execution and algorithm
C program execution and algorithm C program execution and algorithm
C program execution and algorithm
 
Algorithms - Introduction to computer programming
Algorithms - Introduction to computer programmingAlgorithms - Introduction to computer programming
Algorithms - Introduction to computer programming
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
 
INTRODUCTION TO C++, Chapter 1
INTRODUCTION TO C++, Chapter 1INTRODUCTION TO C++, Chapter 1
INTRODUCTION TO C++, Chapter 1
 
02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptx02 Algorithms and flowcharts - computers.pptx
02 Algorithms and flowcharts - computers.pptx
 
01CHAP_1.PPT
01CHAP_1.PPT01CHAP_1.PPT
01CHAP_1.PPT
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
 
Programming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptxProgramming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptx
 
C++ programming program design including data structures
C++ programming program design including data structures C++ programming program design including data structures
C++ programming program design including data structures
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
COM1407: Structured Program Development
COM1407: Structured Program Development COM1407: Structured Program Development
COM1407: Structured Program Development
 
Unit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and FlowchartUnit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and Flowchart
 
PPS Unit-1.pdf
PPS Unit-1.pdfPPS Unit-1.pdf
PPS Unit-1.pdf
 
part_1 (1).ppt
part_1 (1).pptpart_1 (1).ppt
part_1 (1).ppt
 
Pseudo code.pptx
Pseudo code.pptxPseudo code.pptx
Pseudo code.pptx
 
Fundamentals of programming with C++
Fundamentals of programming with C++Fundamentals of programming with C++
Fundamentals of programming with C++
 
Algorithms and flow charts
Algorithms and flow chartsAlgorithms and flow charts
Algorithms and flow charts
 

More from Ashim Lamichhane

Searching
SearchingSearching
Searching
Ashim Lamichhane
 
Sorting
SortingSorting
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
Ashim Lamichhane
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Queues
QueuesQueues
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
Ashim Lamichhane
 
Algorithm big o
Algorithm big oAlgorithm big o
Algorithm big o
Ashim Lamichhane
 
Algorithm Introduction
Algorithm IntroductionAlgorithm Introduction
Algorithm Introduction
Ashim Lamichhane
 
Introduction to data_structure
Introduction to data_structureIntroduction to data_structure
Introduction to data_structure
Ashim Lamichhane
 
Unit 11. Graphics
Unit 11. GraphicsUnit 11. Graphics
Unit 11. Graphics
Ashim Lamichhane
 
UNIT 10. Files and file handling in C
UNIT 10. Files and file handling in CUNIT 10. Files and file handling in C
UNIT 10. Files and file handling in C
Ashim Lamichhane
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
Ashim Lamichhane
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
Ashim Lamichhane
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
Ashim Lamichhane
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
Ashim Lamichhane
 
Unit 5. Control Statement
Unit 5. Control StatementUnit 5. Control Statement
Unit 5. Control Statement
Ashim Lamichhane
 
Unit 4. Operators and Expression
Unit 4. Operators and Expression  Unit 4. Operators and Expression
Unit 4. Operators and Expression
Ashim Lamichhane
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
Ashim Lamichhane
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
Ashim Lamichhane
 

More from Ashim Lamichhane (19)

Searching
SearchingSearching
Searching
 
Sorting
SortingSorting
Sorting
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Linked List
Linked ListLinked List
Linked List
 
Queues
QueuesQueues
Queues
 
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
 
Algorithm big o
Algorithm big oAlgorithm big o
Algorithm big o
 
Algorithm Introduction
Algorithm IntroductionAlgorithm Introduction
Algorithm Introduction
 
Introduction to data_structure
Introduction to data_structureIntroduction to data_structure
Introduction to data_structure
 
Unit 11. Graphics
Unit 11. GraphicsUnit 11. Graphics
Unit 11. Graphics
 
UNIT 10. Files and file handling in C
UNIT 10. Files and file handling in CUNIT 10. Files and file handling in C
UNIT 10. Files and file handling in C
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
Unit 5. Control Statement
Unit 5. Control StatementUnit 5. Control Statement
Unit 5. Control Statement
 
Unit 4. Operators and Expression
Unit 4. Operators and Expression  Unit 4. Operators and Expression
Unit 4. Operators and Expression
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
 

Recently uploaded

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 

Recently uploaded (20)

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 

Unit 1. Problem Solving with Computer

  • 1. Unit 1. Problem Solving with Computer Ashim Lamichhane 1
  • 2. Intro • Number of problems in our daily life. • Suppose we have to calculate Simple Interest. • Suppose we have to prepare a mark sheet. • A computer is a DUMB machine. • A computer cannot do anything alone without software i.e. Program Ashim Lamichhane 2
  • 3. • A software is a set of programs written to solve a particular problem • Software is a set of instructions on the basis of which computer gives output/result. • If the instructions are not correct, the computer gives wrong result. Ashim Lamichhane 3
  • 4. Never Ever Forget • Just writing code is not sufficient to solve a problem. • Program must be planned before coding in any computer language available. • There are many activities to be done before and after writing code. Ashim Lamichhane 4
  • 5. 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
  • 6. Fig. Steps in problem solving Ashim Lamichhane 6 Algorithm Development Flowcharting Documentation Debugging and Testing Compilation and Execution Program Coding Problem Analysis
  • 7. Problem Analysis • Process of becoming familiar with the problem. • We need to analyze and understand it well before solving. • The user’s requirements cannot be fulfilled without clear understanding of his/her problem in depth. • Inadequate identification of problem may cause program less useful and insufficient. • Example: Banking Solution, Hospital Medical Study Ashim Lamichhane 7
  • 8. Algorithm Development • Step By Step description of the method to solve a problem. • Effective procedure for solving a problem in finite number of steps. • Developing an algorithm is a step of program design. Ashim Lamichhane 8
  • 9. An algorithm to find sum of two numbers: Step 1: Start Step 2: Assume two numbers x and y and a variable sum=0 Step 3: Add two numbers x and y; store the value in variable sum Step 4: If you want to try again with different numbers then goto step 2 else goto step 5 Step 5: END Ashim Lamichhane 9
  • 10. 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
  • 11. An algorithm to find largest of three different numbers: Ashim Lamichhane 11
  • 12. 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
  • 13. Flowcharting • Graphical representation of an algorithm using standard symbols. • Includes a set of various standard shaped boxes that are interconnected by flow lines. • Flow lines have arrows(direction of flow). • Activities are written within boxes in English. • Communicates between programmers and business persons. Ashim Lamichhane 13
  • 14. 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
  • 16. Things to consider • There should be start and stop to the flowchart. • Only one flow line should emerge from a process symbol. • Only one flow line should enter a decision symbol, but two or three flow lines can leave the decision symbol. Ashim Lamichhane 16
  • 17. 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
  • 18. Flowchart Ashim Lamichhane 18 START END Read two Numbers, A and B Display C as Sum of A and B C = A + B Input Start Output End Processing
  • 19. Some questions for Assignment • Write an algorithm and draw flowchart to determine a number whether it is positive or negative. • Write an algorithm and draw flowchart to test a number for even or odd. • Write an algorithm and draw flowchart to find the largest number among three numbers. Ashim Lamichhane 19
  • 20. • Read N numbers from user and display sum of all entered numbers. • For finding the sum of the series 1+2+3+4+… up to N terms • For calculating the factorial of a given number N. Ashim Lamichhane 20
  • 21. Coding • The process of transforming the program logic design into computer language format. • An act of transforming operations in each box of the flowchart in terms of the statement of the program. • The code written using programming language is also known as source code. • Coding isn’t the only task to be done to solve a problem using computer. • Anyone can code. TRUST ME!! Ashim Lamichhane 21
  • 22. Compilation • Process of changing high level language into machine level language. • It is done by special software, COMPILER • The compilation process tests the program whether it contains syntax errors or not. • If syntax errors are present, compiler can not compile the code. Ashim Lamichhane 22
  • 23. 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. • The program may ask user for inputs and generates outputs after processing the inputs. Ashim Lamichhane 23
  • 24. Debugging and Testing • Debugging is the discovery and correction of programming errors. • Some errors may remain in the program because the designer/programmer might have never thought about a particular case. • When error appears debugging is necessary. Ashim Lamichhane 24
  • 25. Debugging and Testing • Testing ensures that program performs correctly the required task. • Verification ensures that program does what the programmer intends to do. • Validation ensures that the program produces the correct results for a set of test data. • Test data are supplied to the program and output is observed. • Expected output = Error free Ashim Lamichhane 25
  • 26. Program Documentation • Helps to those who use, maintain and extend the program in future. • A program may be difficult to understand even to programmer who wrote the code after some days. • Properly documented program is necessary which will be useful and efficient in debugging, testing, maintenance and redesign process. Ashim Lamichhane 26
  • 27. Two types of documentations 1. Programmer’s Documentation (Technical Documentation) • Maintain, redesign and upgrade • Logic, DFD, E-R, algorithm and flowchart 2. User Documentation (User Manual) • Support to the user of the program • Instructions for installation of the program Ashim Lamichhane 27
  • 29. Computer Program • Set of instructions that causes to behave in predetermined manner. • To instruct a computer to perform a certain job, we need languages, but not English or Nepali(!!!FOR NOW!!!). • We need languages understood by the computer. Ashim Lamichhane 29
  • 30. Types or levels of Programming Languages • High Level • Low-level – Machine Level – Assembly Level Ashim Lamichhane 30
  • 31. Low Level Language • Statement or instruction is directly translated into a single machine code. • It is machine dependent, i.e. A particular low- level language works only for a certain machine. Ashim Lamichhane 31
  • 32. 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
  • 33. • To add two number in machine language: 11 10111001 110 3 machine code for addition (say) 6 • It is difficult to remember different instructions for programming. Ashim Lamichhane 33
  • 34. Machine Level Language ADVANTAGE DISADVANTAGE Computer directly understands machine instructions Difficult to use Directly starts executing Machine dependent Takes less execution time Difficult to Debug and modify Ashim Lamichhane 34
  • 35. Assembly Language • Symbolic representation(mnemonics) of machine code. • Close to machine code but the computer cannot understand • Must be translated into machine code by a separate program called an assembler. 11 ADD 110 – Suppose ADD is mnemonic for addition Ashim Lamichhane 35
  • 36. 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 It is relatively easy for writing programs in assembly languages, but is slow in execution as it has to be converted into machine language before execution.
  • 37. 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
  • 38. High Level Language • User friendly, Similar to natural languages • Platform independent • Easy to write or remember • Easy to learn and work • While execution: translated into assembly language then to machine language. • Slow in execution but is efficient for developing programs. • Ex: C, C++, Python, Java etc. Ashim Lamichhane 38
  • 39. 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
  • 40. Compiler • A high level source program must be translated into a form machine can understand. This done by software called the compiler. • Source code => Machine language code(Object code) • During the process of translation, the compiler reads the source programs statement-wise and checks for syntax errors. • In case of any error, the computer generates message about the error. • Ex: C, C++, Java, FORTRAN, pascal etc. Ashim Lamichhane 40
  • 41. Interpreter • Like compiler, it is also a translator which translates high level to machine level language. • Translates and executes the program line by line. • Each line is checked for syntax error and then converted to the equivalent machine code. • Ex. QBASIC, PERL, PHP, ASP, PYTHON, RUBY Ashim Lamichhane 41
  • 42. Difference between compiler and interpreter Compiler Interpreter Compiler scans the entire program before translating it into machine code Interpreter translates and executes the program line by line Syntax errors are found only after the compilation of complete programs Syntax errors can be trapped after translations of every line It takes large amount of time to analyze the source code but the overall execution time is comparatively faster. It takes less amount of time to analyze the source code but the overall execution time is slower. Generates intermediate object code which further requires linking, hence requires more memory. No intermediate object code is generated, hence are memory efficient. Ashim Lamichhane 42
  • 43. Overview to C Programming Ashim Lamichhane 43
  • 44. • We can assume C as middle level language • This doesn’t mean C is less power full or harder to use or less developed. • Instead C combines the advantages of high level language with the functionalism of assembly language. • Like high level, C provides block structures, stand-alone functions and small amount of data typing. • Like assembly language, it allows manipulations of bits, bytes, pointers and it is mostly used in system programming. • Combination of two aspects. Ashim Lamichhane 44
  • 45. History of C programming language • C is a programming language which was born at “AT & T’s Bell Laboratory” of USA in 1972. • C was written by Dennis Ritchie, that’s why he is also called as father of C programming language. • C language was created for a specific purpose i.e. designing the UNIX operating system (which is currently base of many UNIX based OS). • From the beginning, C was intended to be useful to allow busy programmers to get things done because C is such a powerful, dominant and supple language. • It’s use quickly spread beyond Bell Labs in the late 70’s Ashim Lamichhane 45
  • 46. Why use C? • Robust Language • Efficient and fast • Highly portable • Structured Language • Extendibility • Middle level language • Rich system library Ashim Lamichhane 47
  • 47. Executing a C Program Ashim Lamichhane 48
  • 48. Basic Structure of C Program Ashim Lamichhane 49
  • 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
  • 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
  • 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
  • 52. 4. Global Declaration Section - The variables which are used in more than one functions or blocks are called global variables. - This section also declares all the user-defined functions. Ashim Lamichhane 53
  • 53. 5. main() Function Section - Every C program starts with a main() function. - Declaration part and executable part - Declaration part declares all the variables used in the execution part. - int n1; - int n2=5; - Execution part has executable operations like: - n1= n1 +1; - n2=n1*5 Ashim Lamichhane 54
  • 54. 6. Subprogram Section - This section contains all the user-defined functions that are called in the main function. - All the sections except the main function section may be absent when they are not required. Ashim Lamichhane 55
  • 55. Note • For Assignments And Lecture Slides https://github.com/ashim888/csit-c http://www.ashimlamichhane.com.np/ Ashim Lamichhane 56