0% found this document useful (0 votes)
18 views

Unit 1 (Problem Solving With Computer)

Uploaded by

rishavkhadka43
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Unit 1 (Problem Solving With Computer)

Uploaded by

rishavkhadka43
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

C Programming (CSC110)

Sulav Nepal
Email: nep.sulav@live.com
Contact No.: 9849194892
Master’s in Computer Information System (MCIS) – Pokhara University
Bachelor of Science. Computer Science & Information Technology (B.Sc. CSIT) – Tribhuwan University
Microsoft Technology Associate (MTA): Windows Server Administration Fundamentals
Microsoft Certified Technology Specialist (MCTS): Windows Server 2008 R2, Server Virtualization
Microsoft Specialist (MS): Programming in HTML5 with JavaScript and CSS3
Microsoft Students Partner (MSP) 2012 for Nepal
P P
R R
E E
P P
A A
R R
E E
D D

B
Y not ENGLISH nor NEPALI B
Y

S S
U U
L
A Welcome to C Programming Language L
A
V V

N N
E E
P P
A A
L L

2 12/25/2023 8:00 AM
P P
R R
E
P
Syllabus E
P
A  UNIT 1: Problem Solving with Computer A
R R
E E
D
o Problem Analysis D

B B
Y Y
o Algorithms and Flowchart
S S
U U
L o Coding, Compilation, & Execution L
A A
V V
o History of C
N N
E E
P o Structure of C program P
A A
L L
o Debugging,Testing & Documentation
3 12/25/2023 8:00 AM
P P
R R
E E
P P
A A
R R

UNIT 1
E E
D D

B B
Y Y

S PROBLEM SOLVING WITH COMPUTER S


U U
L L
A A
V V

N N
E E
P P
A A
L L

4 12/25/2023 8:00 AM
P P
R
E Introduction R
E
P P
A
R
 Number of problems in our daily life. A
R
E E
D D
 Suppose we have to calculate Simple Interest.
B B
Y Y

S  Suppose we have to prepare a mark sheet. S


U U
L L
A A
V  A computer is a DUMB machine. V

N N
E E
P  A computer cannot do anything alone without software. i.e. P
A
L Program. A
L

5 12/25/2023 8:00 AM
P P
R
E Introduction R
E
P P
A A
R R
E
D
 A software is a set of programs written to solve a particular problem. E
D

B B
Y  Program is a set of instructions on the basis of which computer gives Y

S output/result. S
U U
L L
A A
V  If the instructions are not correct, the computer gives wrong result. V

N N
E E
P P
A A
L L

6 12/25/2023 8:00 AM
P P
R
E Never Ever Forget R
E
P P
A A
R R
E
D
 Just writing code is not sufficient to solve a problem. E
D

B B
Y  Program must be planned before coding in any computer language Y

S available. S
U U
L L
A A
V  There are many activities to be done before and after writing code. V

N N
E E
P P
A A
L L

7 12/25/2023 8:00 AM
P P
R
E Types of Programming Languages R
E
P P
A  Machine Level Language A
R R
E
 Language that a computer actually understands (1’s and 0’s)
E
D  Sequence of instructions written in the form of binary numbers D
 Executes fast as computer don’t need any translation
B B
Y Y
 Assembly Language
S
 Symbolic representation of machine code S
U U
L  Close to machine code but the computer cannot understand L
A  Must be translated into machine code by a separate program called an A
V assembler V

N N
E  High Level Language E
P P
A
 Similar to natural language resulting to ease in learning and writing
A
L  While execution: translated into assembly language then to machine language L
 Slow in execution but is efficient for developing programs
8 12/25/2023 8:00 AM
P P
R
E Overview to C Programming R
E
P P
A  We can assume C as middle level language A
R R
E E
D  This doesn’t mean C is less powerful or harder to use or less developed D

B B
Y  Instead C combines the advantages of high level language with the Y

S
functionalism of assembly language
S
U U
L
 Like high level, C provides block structures, stand-alone functions and L
A A
V small amount of data typing V

N N
E  Like assembly language, C allows manipulations of bits, bytes, pointers and
E
P it is mostly used in system programming P
A A
L L
 Combination of two aspects
9 12/25/2023 8:00 AM
P
R
Stages while solving a problem using P
R
E
P computer E
P
A  Problem Analysis A
R R
E E
D D
 Algorithm Development
B B
Y Y
 Flowcharting
S S
U U
L  Coding L
A A
V V

N  Compilation & Execution


N
E E
P P
A  Debugging & Testing A
L L

10  Documentation 12/25/2023 8:00 AM


P
R
Stages while solving a problem using P
R
E
P computer E
P
A A
R R
E E
D D

B B
Y Y

S S
U U
L L
A A
V V

N N
E E
P P
A A
L L

11 12/25/2023 8:00 AM
P P
R
E Problem Analysis R
E
P P
A
R
 Process of becoming familiar with the problem A
R
E E
D D
 We need to analyze and understand it well before solving
B B
Y Y

S  The user’s requirements cannot be fulfilled without clear S


U U
L understanding of his/her problem in depth L
A A
V V

N  Inadequate identification of problem may cause program less useful N


E
P
and insufficient E
P
A A
L L
 Example: Banking Solution, Hospital Medical Study
12 12/25/2023 8:00 AM
P P
R
E Algorithm Development R
E
P P
A  Step by step description of the method to solve a problem A
R R
E E
D D
 Effective procedure for solving a problem in finite number of steps
B B
Y Y

S
 Developing an algorithm is a step of program design
S
U U
L L
A  Example:An algorithm to find sum of two numbers: A
V V
 Step 1: Start
N  Step 2: Declare variables num1, num2, and sum N
E E
P  Step 3: Read values num1 and num2 P
A  Step 4:Add num1 and num2 and assign the result to sum A
L L
 Step 5: Display sum 𝑠𝑢𝑚 ← 𝑛𝑢𝑚1 + 𝑛𝑢𝑚2
13  Step 6: Stop 12/25/2023 8:00 AM
P P
R
E Algorithm Development R
E
P P
A  Three features of Algorithm: A
R R
E E
D  Sequence D
 Each step in the algorithm is executed in specified order. If not algorithm will fail.
B B
Y Y
 Decision
S  We have to make decision to do something
S
U  If the outcome of the decision is true, one thing is done otherwise other U
L If condition then process1 L
A OR A
V V
If condition then process1 Else process2
N N
E  Repetition E
P Repeat P
A A
L Fill water in kettle
L
Until Kettle is full
14 12/25/2023 8:00 AM
P P
R
E Flowcharting R
E
P P
A A
R  Graphical representation of an algorithm using standard symbols R
E E
D D

B  Includes a set of various standard shaped boxes that are


B
Y interconnected by flow lines Y

S S
U U
L  Flow lines have arrows (direction of flow) L
A A
V V

N  Activities are written within boxes in English N


E E
P P
A A
L  Communicates between programmers and business persons L

15 12/25/2023 8:00 AM
P P
R
E Flowcharting - Advantages R
E
P P
A  Communication – quickly provide logic, ideas, and descriptions of A
R R
E algorithms E
D D

B  Effective Analysis – clear overview of the entire problem B


Y Y

S  Proper Documentation – documents the steps followed in an algorithm and S


U U
L helps us understand its logic in future L
A A
V V
 Efficient Coding – more ease with comprehensive flowchart as a guide
N N
E E
P  Easy in Debugging & Program Maintenance – debugging and maintenance P
A A
L of operating program L

16 12/25/2023 8:00 AM
P P
R
E Flowchart Symbols R
E
P P
A A
R R
E E
D D

B B
Y Y

S S
U U
L L
A A
V V

N N
E E
P P
A A
L L

17 12/25/2023 8:00 AM
P P
R
E Flowchart – Things to Consider R
E
P P
A A
R R
E
D
 There should be start and stop to the flowchart E
D

B B
Y  Only one flow line should emerge from a process symbol Y

S S
U U
L  Only one flow line should enter a decision symbol, but two or three L
A A
V flow lines can leave the decision symbol V

N N
E E
P P
A A
L L

18 12/25/2023 8:00 AM
P P
R
E Example – Sum of Two Numbers R
E
P P
A
R
 Algorithm A
R
E  Step 1: Start E
D D

B B
Y  Step 2: Display “Enter two numbers”
Y

S S
U  Step 3: Read 𝐴 and 𝐵 U
L L
A A
V
 Step 4: 𝐶 = 𝐴 + 𝐵 V

N N
E E
P  Step 5: Display “𝐶 as sum of two numbers” P
A A
L L
 Step 6: Stop
19 12/25/2023 8:00 AM
P P
R
E Example – Sum of Two Numbers R
E
P P
A
R
 Flowchart A
R
E E
D D

B B
Y Y

S S
U U
L L
A A
V V

N N
E E
P P
A A
L L

20 12/25/2023 8:00 AM
P P
R
E Coding R
E
P P
A  The process of transforming the program logic design into computer A
R R
E language format E
D D

B  An act of transforming operations in each box of the flowchart in terms of B


Y the statement of the program Y

S S
U U
L  The code written using programming language is also known as source
L
A code A
V V

N  Coding isn’t the only task to be done to solve a problem using computer. N
E E
P P
A A
L Anyone can code.TRUST ME !! L

21 12/25/2023 8:00 AM
P P
R
E Compilation R
E
P P
A
R
 Process of changing high level language into machine level language A
R
E E
D D
 It is done by special software, called Compiler
B B
Y Y

S  The compilation process tests the program whether it contains syntax S


U U
L errors or not L
A A
V V

N  If syntax errors are present, compiler can not compile the code. N
E E
P P
A A
L L

22 12/25/2023 8:00 AM
P P
R
E Execution R
E
P P
A A
R R
E
D
 Once the compilation is completed then the program is linked with E
D
other object programs needed for execution, there by resulting in a
B B
Y binary program and then the program is loaded in the memory for Y
the purpose of execution and finally it is executed
S S
U U
L L
A  The program may ask user for inputs and generates outputs after A
V V
processing the inputs
N N
E E
P P
A A
L L

23 12/25/2023 8:00 AM
P P
R
E Debugging and Testing R
E
P P
A A
R R
E
D
 Debugging is the discovery and correction of programming errors. E
D

B B
Y  Some errors may remain in the program because the Y

S designer/programmer might have never thought about a particular S


U
L
case. U
L
A A
V V

N
 When error appears debugging is necessary.
N
E E
P P
A A
L L

24 12/25/2023 8:00 AM
P P
R
E Debugging and Testing R
E
P P
A
R
 Testing ensures that program performs correctly the required task A
R
E E
D D
 Verification ensures that program does what the programmer intends
B B
Y to do Y

S S
U U
L  Validation ensures that the program produces the correct results for a L
A
V
set of test data A
V

N N
E  Test data are supplied to the program and output is observed E
P P
A A
L L
 Expected output = Error free
25 12/25/2023 8:00 AM
P P
R
E Program Documentation R
E
P P
A A
R R
E
D
 Helps to those who use, maintain, and extend the program in future E
D

B B
Y  A program may be difficult to understand even to programmer who Y

S wrote the code after some days S


U U
L L
A A
V  Properly documented program is necessary which will be useful and V

N
efficient in debugging, testing, maintenance, and redesign process
N
E E
P P
A A
L L

26 12/25/2023 8:00 AM
P P
R
E Program Documentation - Types R
E
P P
A A
R R
E
D
 Programmer’s Documentation (Technical Documentation) E
D
 Maintain, redesign, and upgrade
B B
Y  Logic, DFD, ER Diagram, algorithm, & flowchart Y

S S
U U
L  User Documentation (User Manual) L
A
V
 Support to the user of the program A
V
 Instructions for installation of the program
N N
E E
P P
A A
L L

27 12/25/2023 8:00 AM
P P
R
E History of C Programming R
E
P P
A  C is a programming language which was born at “AT & T’s Bell Laboratory” A
R of USA in 1972 R
E E
D D
 C was written by Dennis Ritchie, that’s why he is also called as father of C
B B
Y programming language
Y

S S
U  C language was created for a specific purpose i.e. designing UNIX
U
L operating system (which is currently base of many UNIX based OS) L
A A
V V
 From the beginning, C was intended to be useful to allow busy
N programmers to get things done because C is such a powerful, dominant N
E and supple language E
P P
A A
L  Its use quickly spread beyond Bell Labs in the late 70’s L

28 12/25/2023 8:00 AM
P P
R
E Why use C? R
E
P P
A  Robust language A
R R
E E
D D
 Efficient and fast
B B
Y Y
 Highly portable
S S
U U
L  Structured language L
A A
V V

N  Extendibility
N
E E
P P
A  Middle level language A
L L

29  Rich system library 12/25/2023 8:00 AM


P P
R
E Basic Structure of C Program R
E
P P
A A
R R
E E
D D

B B
Y Y

S S
U U
L L
A A
V V

N N
E E
P P
A A
L L

30 12/25/2023 8:00 AM
P P
R
E Basic Structure of C Program R
E
P P
A
R
 Document Section A
R
E  Sets of comment line giving the name of program, the author, E
D D
algorithms, methods used, and other details
B B
Y Y
 Acts as a communication between members of the development team
S S
U U
L
A
 Acts as user manual L
A
V V

N  Example: /* This program adds two numbers */ N


E E
P P
A A
L L

31 12/25/2023 8:00 AM
P P
R
E Basic Structure of C Program R
E
P P
A
R
 Link Section A
R
E  Provides instructions to the compiler to link functions with program E
D D
from the system library
B B
Y Y
 Example: #include<stdio.h>
S S
U  Links input/output functions like printf() and scanf() with the program
U
L L
A A
V V

N N
E E
P P
A A
L L

32 12/25/2023 8:00 AM
P P
R
E Basic Structure of C Program R
E
P P
A
R
 Definition Section A
R
E  In this section all symbolic constants are defined E
D D

B B
Y  This section may be included or excluded while writing a C program
Y

S S
U  Example: U
L L
A #define PI 3.1416
A
V #define FORMULA 3*x*x*x+2*x*x V

N N
E E
P P
A A
L L

33 12/25/2023 8:00 AM
P P
R
E Basic Structure of C Program R
E
P P
A
R
 Global Declaration Section A
R
E  The variables which are used in more than one functions or blocks are E
D D
called global variables
B B
Y Y
 This section also declares all the user-defined functions
S S
U U
L
A
 This section may be included or excluded while writing a C program L
A
V V

N N
E E
P P
A A
L L

34 12/25/2023 8:00 AM
P P
R
E Basic Structure of C Program R
E
P P
A
R
 Main() Function Section A
R
E  Every C program starts with a main() function E
D D
 Declaration part and Executable part
B B
Y Y
 Declaration part declares all the variables used in the execution part
S S
U  int n1;
U
L  int n2=5; L
A A
V V
 Execution part has executable operations like
N N
E  n1=n1+1; E
P P
 n2=n1*5;
A A
L L

35 12/25/2023 8:00 AM
P P
R
E Basic Structure of C Program R
E
P P
A
R
 Subprogram Section A
R
E  This section contains all the user-defined functions that are called in E
D D
the main function.
B B
Y Y
 All the sections except the main function section may be absent when
S S
U they are not required U
L L
A A
V V

N N
E E
P P
A A
L L

36 12/25/2023 8:00 AM
P P
R
E First C Program R
E
P P
A
R
//First program in C A
R
E
D
#include<stdio.h> E
D

B
#include<conio.h>
B
Y void main() Y

S { S
U U
L printf("This is my first program in C"); L
A A
V getch(); V

N } N
E E
P P
A A
L L

37 12/25/2023 8:00 AM
P P
R R
E E
P P
A A
R R
E E
D D

B B
Y Y

S
END OF UNIT ONE
S
U U
L L
A A
V V

N N
E E
P P
A A
L L

38 12/25/2023 8:00 AM

You might also like