CS101E-PSP- Part I
CS101E-PSP- Part I
*
Learning Outcomes
COURSE OUTCOMES
*
Module Content
*
Problem Solving Aspects
Problem solving is a creative process. It is an act of defining a problem, determining
the cause of the problem, identifying, prioritizing, and selecting alternatives for a
solution and implementing a solution.
A Problem can be solved successfully only after making an effort to understand the
problem. To understand the problem, the following questions help:
• What do we know about the problem?
• What is the information that we have to process in order the find the solution?
• What does the solution look like?
• What sort of special cases exist?
• How can we recognize that we have found the solution?
*
Methodology
Different strategies appear to be good for different problems.
Some of the well known strategies are:
*
Program Development
The various steps involved in Program Development are:
*
Algorithms
Definition :
The term “ordered sequence” specifies, after the completion of each step in
the algorithm, the next step must be unambiguously defined.
An algorithm must be:
• Definite
• Finite
• Precise and Effective
• Implementation independent ( only for problem not for programming languages)
*
Algorithms
Example 1: Algorithm for finding factorial of a given number
Step 1: Start
Step 2: Initialize factorial to be 1, i to be 1
Step 3: Input a number n
Step 4: Check whether the number is 0. If so report factorial is 1 and go to step 9
Step 5: Repeat step 6 through step 7 n times
Step 6: Calculate factorial = factorial * i
Step 7: Increment i by 1
Step 8: Report the calculated factorial value
Step 9: Stop
*
Pseudo Code
Example 1: Pseudo Code for finding factorial of a given number
Step 1: START
Step 2: DECLARE the variables n, fact, i
Step 2: SET variable fact =1 and i =1
Step 3: READ the number n
Step 4: IF n = 0 then
Step 4.1: PRINT factorial = 1
Step 4.2: GOTO Step 9
Step 5: WHILE the condition i<=n is true, repeat Step 6 through Step 7
Step 6: COMPUTE fact = fact * i
Step 7: INCREMENT i by 1
Step 8: PRINT the factorial value
Step 9: STOP
*
Flowchart
Definition
*
Flowchart Symbols
Typical flowchart symbols are given below
*
Flowchart
*
Algorithms
*
Flowchart
*
Algorithms
*
Flowchart
*
Algorithms
*
Flowchart
*
Algorithms
*
Flowchart
*
Introduction to C
Language
C is a general purpose high level programming
language. Because of its flexibility and efficiency it is
widely used for software development. Its features
allow the development of well-structured programs.
*
Evolution of C Language
ALGOL was the first computer language to use a block
structure. In 1967, Martin Richards developed a language
called BCPL (Basic Combined Programming Language)
primarily, for writing system software.
In 1970, Ken Thompson created a language using many
features of BCPL and called it ‘B’. ‘B’ was used to create
early versions of UNIX operating system at Bell
Laboratories. Both BCPL and B were “typeless” system
programming languages.
*
Evolution of C Language
*
ANSI C - Standard
*
Characteristics of C
Language
⚫ C language is well suited for structured modular programming
⚫ C is a robust language with rich set of built-in functions and operators
⚫ C is smaller which has minimal instruction set and programs written
in C are efficient and fast
⚫ C is highly portable (code written in one machine can be moved to
other)
⚫ C is highly flexible
⚫ C allows access to the machine at bit level (Low level (Bitwise)
programming)
⚫ C supports pointer implementation - extensive use of pointers for
memory, array,
structures and functions
*
Character Set
*
Variable and Constants
A variable is a named data storage location in computers memory. By
using a variable name we are referring to the data stored in the location. A
value that changes during the
execution of the program is called variable.
Rules of variables declaration in C:
*
Integer Constants
*
Floating Point Constants
*
Char and String Constants
*
Symbolic Constants
*
Datatypes
1.Fundamental
2.Derived
*
Datatypes
*
Datatypes
*
Variable Declaration
*
Assignment Statement
*
Precedence of Operators
*
Mathematical Functions
*
Structure of a C Program
*
Structure of C Program
*
Building a C Program
*
Keywords
Keywords are reserved identifiers and they cannot be used
as names for the program variables. The keywords are also
called as reserved words. The meaning of the keywords
already given to the compiler. There are 32 keywords
available in C.
*
Variable and Constants
A variable is a named data storage location in computers
memory. By using a variable name we are referring to the
data stored in the location. A value that changes during the
execution of the program is called variable.
Rules of variables declaration in C:
Integer constant
Floating point constant
Character constant
String constant
*
Types of Constants
*
Datatypes
A data types defines a set of values that a variable
can store along with a set of operation that can be
performed on the variable. There are basically two
types of data types:
1. Fundamental
2. Derived
*
Datatypes
*
Datatypes
*
Algorithms
C supports a rich set of operators. An operator is a
symbol that tells the computer to perform
mathematical or logical operations. Operators are
used in programs to manipulate data.
C operators can be classified into a number of
categories. They include
*
Operators
*
Operators
*
Priority of Operators
*
Expressions
Expression is a combination of
operands, operators, function calls that
evaluates to a value. The three types of
expressions are
*
Algorithms
*
Typedef
C automatically converts any intermediated values
to the proper type so that the
expression can be evaluated without losing any
significance. This auto
known implicit type conversion
Type casting is a way to convert a variable from one
data type to another data type. For
example, if you want to store a long va
int. One can convert values from one type to another
explicitly using the
follows:
(type_name) expression
*
Typedef
Consider the following example where the
cast operator causes the division of one
integer variable by another to be performed
as a floating-point operation:
#include <stdio.h>
main()
{
int sum = 17, count = 5;
double mean;
mean = (double) sum / count;
printf("Value of mean : %f\n", mean );}
*
Summary
Thus we have discussed the basic concepts of C Language.
1. Algorithms
2. Flowcharts
3. Structure of C program
4. Data types
5. Variables, Constants
6. Opeartors
7. Expressions