UNIT I Full
UNIT I Full
Guided By
Prof. Supriya G.Jadhav
Teaching & Credit Examination Scheme
FPL Theory
l Credits: 2
l Mid Semester(TH): 30 Marks
l End Semester(TH): 70 Marks
l Total: 100 Marks
FPL Lab
l Credit: 1
l TermWork: 25 Marks
l Total: 25 Marks
Prerequisite Courses : Basics of Computers, Basic Mathematics
l
Importance in placement interviews
Course Objectives
• To understand the fundamental Concepts of C Programming
• To acquire knowledge and Compare usage of Operators and Expressions in C
Programming
• To apply Control Flow structures in C Programming for Problem solving
• To design a solution using Arrays, Character and String Arrays in C
programming
• To design a develop solution for simple computational problems using User
Defined Functions in C Programming
• Justify the use of structures in Problem solving using C programming language
UNIT- I: Introduction to Program
Planning & C Programming
UNIT 1 to 5
UNIT- II: Operators and
Expressions
l
1.Program Design Tools: Art of Programming
through Algorithms, Flowcharts.
l
2.Overview of C:History and importance C,
Character Set, C Tokens, Keywords and
Identifiers.
l
3.Constants, Variables, Data types, Declaration
of variables, Storage Class, Assigning Values
to variables.
l
4.Defining Symbolic Constants, declaring a
Variable as Constant, Declaring a Variable as
Volatile.
Algorithm
l
Algorithm:
l
Def:
l
It is defined as a finite set of instructions that
describe a method for solving a problem. In other
words it is a step by step procedure for solving a
problem.
l
Systematic procedure that produces - in a finite
number of steps - the answer to a question or the
solution of a problem.
l
Sequence of instructions which can be used to
solve a given problem
Examples
l
Example 1: l
Write an algorithm to print all
l
Write an algorithm to check l
natural numbers up to n
l
whether he is eligible to
l
Step 1: Start
vote?
l
Step 2: get n value.
l
Step 1: Start
l
Step 3: initialize i=1
l
Step 4: if (i<=n) go to step 5
l
Step 2: Get age
else go
l
Step3: if age >= 18 print l
to step 7
l
“Eligible to vote” l
Step 5: Print i value and
l
Step 4: else print “Not increment i
l
eligible to vote” l
value by 1
l
Step 6: Stop l
Step 6: go to step 4
l
Step 7: Stop
Write an Algorithm
l
To find the average of three numbers taken as
input from the user.
l
The process of boiling an egg
l
The process of mailing a letter.
l
To divide one number by another & find the
quotient.
l
To find the maximum of two nos. Input by the
user.
l
l
ALGORITHM- POINTS TO
NOTE
l
1. The process consists of repeated application of
simple steps
l
2. All steps are unambiguous (clearly defined)
l
3. We are capable of doing all those steps
l
4. Only a limited no. of steps needs to be taken
l
5. Once all those steps are taken according to the
prescribed sequence, the required result will be found
l
6. Moreover, the process will stop at end point.
l
THREE REQUIREMENTS
l
1.Sequence is
l
a. accurate
l
b. Consists of a limited number of steps
l
2.Each step is:
l
a. Unambiguous
l
b. Executable
l
3.The sequence of steps terminates in the form
of a solution
l
Flowchart
l
Flowchart is a graphical representation of
alogorithm, in which graphic objects are used to
indicate the steps & decisions that are taken as
the process moves along from start to finish.
l
Individual steps are represented by boxes and
other shapes on the flowchart, with arrows
between those shapes indicating the order in
which the steps are taken.
Symbols of Flowcharts
Addition of two numbers
l
DRAW FLOWCHART
l
1. Multiplication of two Nos.
l
2. To display large no. From two nos.
l
3. Draw flowchart to calculate Area of circle.
l
Pseudo code
l
Pseudo code is the artificial and informal
language that is typically used for writing
algorithms.
l
SimilarIy to a programming language, but not as
rigid
l
is text based algorithmic design tool.
l
Pseudo code can be developed using different
computer operations.
Psudocode for Addition
1.Begin
2.WRITE “Please enter two numbers to add”
3.READ num1.
4.READ num2.
5.Sum = num1+num2.
6.WRITE Sum.
7.End
Psudocode for Area of circle
1.Begin
2.NUMBER r, area
3.INPUT r
4.area=3.14*r*r
5.OUTPUT area
6.End
Computer Concepts -
Introduction to Computer
BACKGROUND
In today's world, we use computers for all our tasks. Our
day-to-day activities: paying bills, buying groceries, using
social media, seeking entertainment, working from home,
communicating with a friend, etc., can all be done using a
computer.
So it is important not only to know how to use a computer,
but also to understand the components of a computer and
what they do.
What is a Computer?
A computer is an electronic device that accepts data from
the user, processes it, produces results, displays them to the
users, and stores the results for future usage.
Data is a collection of unorganized facts & figures and does
not provide any further information regarding patterns,
context, etc. Hence data means "unstructured facts and
figures".
Information is a structured data i.e. organized meaningful
and processed data. To process the data and convert into
information, a computer is used.
Computer Basics
What do you mean by Computer …?
It is an electronic device that is able to take raw input or “data” from
a user, store it, process it and output information as per requirement.
Eg: Online booking tickets (Railway, Plane and Bus), ATM Machine ,
update our bank passbook.
Evolution Of Computers
Two ERA’s
• Machine Era (Before 1965)
• Electronic Era (1945 –till Date)
• Generation of Computers:
First Generation (1945-1954)
Use of bulky electric tubes i.e Vaccum Tubes
Large Space
Slow Speed
Second Generation (1955-1964)
Use of Transistors
Reduced Size
Third Generation (1965-1974)
Use of IC’s
Low Cost
High Processing Speed
Accuracy
a)Input
b)Process
c)Output
d)Storage
Input Devices:
Means to collect information from user and insert into the
computer.
Eg: Keyboard, Mouse, Joystick, Scanner etc.
Central Processing Unit:
CPU contains electronic circuits that cause processing to occur.
CPU interprets Instructions.
CPU performs logical and arithmetic operations.
CPU is brain of the computer.
CPU has two parts:
1)Control Unit:
It controls signals between memory and ALU.
1)Arithmetic and Logic Unit:
It performs arithmetic and logic operations.
Memory:
Memory is also called as Random Access Memory(RAM) i.e
Temporary Memory.
RAM is main memory of the computer.
RAM is electronic component that store data i.e numbers, letters,
alphabets, graphics and sound.
STORAGE DEVICE :
The auxiliary storage device are 1) Floppy Disk 2)Hard Disk
3)CD-ROM’s 4)Pendrive
Central Processing Unit
The Central
Processing Unit (CPU)
is called "the brain of
computer" as it
controls operation of
all parts of computer.
l
1.Program Design Tools: Art of Programming
through Algorithms, Flowcharts.
l
2.Overview of C:History and importance C,
Character Set, C Tokens, Keywords and
Identifiers.
l
3.Constants, Variables, Data types, Declaration
of variables, Storage Class, Assigning Values
to variables.
l
4.Defining Symbolic Constants, declaring a
Variable as Constant, Declaring a Variable as
Volatile.
History of C Programming
Language
C is a programming language which born at “AT & T’s Bell
Laboratory” of USA in 1972.
Its use quickly spread beyond Bell Labs in the late 70’s
because of its long list of strong features
Let us see programming language
developed before C
Why Name “C” was given to
Language?
Many of C’s principles and ideas were derived from
the earlier language B. (Ken Thompson was the
developer of B Language.)
BCPL and CPL are the earlier ancestors of B
Language
CPL is common Programming Language. In 1967,
BCPL Language ( Basic CPL ) was created as a
scaled down version of CPL
As many of the features were derived from “B”
Language that’s why it was named as “C”. After 7-8
years C++ came into existence which was first
example of object oriented programming.
C programming language has
following importances:
C is robust language and has rich set of built-
in functions, data types and
operators which can be used to write any
complex program.
Program written in C are efficient due to
availability of several data types and operators.
C has the capabilities of an assembly language
(low level features) with the feature of high
level language so it is well suited for writing
both system software and application
software.
C is highly portable language i.e. code
written in one machine can be moved to other
which is very important and powerful feature.
C supports low level features like bit level
programming and direct access to memory
using pointer which is very useful for
managing resource efficiently.
C has high level constructs and it is more user
friendly as its syntaxes approaches to English
like language.
HIGH LEVEL LANGAUAGE
With the help of high level language one can write
applications that are portable across various platforms
and is independent of any architecture.
High level languages are easier to understand and is
user-friendly.
High level languages has lots of abstractions and layers
of code before they reach the hardware itself.
High level languages are extremely portable, they are
mostly used to write software’s which can run on
multiple platforms and architectures.
High level is where all the creative things take place
and it can be debugged in very easier manner than a
low-level.
LOW LEVEL LANGUAGE
Low Level languages, these languages are very close to
machine language, they are also known as assembly
language.
Low Level languages are more appropriate for
developing new operating systems or writing firmware
codes for micro-controllers.
Low level, machine code is nearer to the hardware,
which is actually fast to process and return the output.
Low Level languages codes are very hard to understand,
and code written in assembly language is impossible to
run on other machine or architecture.
low level is challenging and requires a great deal of
experience and knowledge
CONCEPT OF HARDWARE AND
SOFTWARE
Hardware:
physical component of a computer is called as
hardware. The hardware may be an electronic,
electrical, magnetic or mechanical components
1)System Software
2) Application software
System Software:
The System Software is basically used by the
computer system to control all the actions and
operations of the system.
2) Assembly Language
1.Alphabets
C language supports all the alphabets from the
English language.
Lower and upper case letters together support
52 alphabets.
lower case letters - a to z
UPPER CASE LETTERS - A to Z
2. Digits
C language supports 10 digits which are used to
construct numerical values in C language.
Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
3.Special Symbols
C language supports a rich set of special symbols that
include symbols :
to perform mathematical operations,
to check conditions, white spaces, backspaces, and other
special symbols.
Special Symbols - ~ @ # $ % ^ & * ( ) _ - + = { } [ ] ; : '
" / ? . > , < \ | tab, newline space, NULL bell
backspace ,verticaltab etc.
Tokens in C
Identifiers in C
Strings in C
Operators in C
Constant in C
Special Characters in C
Keywords in C
1.All keywords have fixed meanings & these
meaning cannot be changed.
2.Keywords are the pre-defined words used by
the compiler.
distinct.
Therefore, we can say that identifiers are case sensitive.
Commas or blank spaces cannot be specified within an
identifier.
Keywords cannot be represented as an identifier.
The length of the identifiers should not be more than 31
characters.
Operators in C
Operators in C is a special symbol used to
perform the functions. The data items on which
the operators are applied are known as operands.
Operators are applied between the operands.
Depending on the number of operands, operators
are classified as follows:
1. Unary Operator
2. Binary Operator
Unary Operator
Arithmetic Operators
Relational Operators
Shift Operators
Logical Operators
Bitwise Operators
Conditional Operators
Assignment Operator
Constants in C
A variable is a data name that may be used to store a data value. Unlike constants that remain
unchanged during the execution of a program, a variable may take different values at different times
during execution.
A variable name can be chosen by the programmer in a meaningful way so as to reflect its function
e.g.
Average
height
Total
Counter_1
class_strength
Variables in C
A variable in C language is the name associated with
some memory location to store data of different types.
There are many types of variables in C depending on
the scope, storage class, lifetime, type of data they
store, etc.
A variable is the basic building block of a C program
that can be used in expressions as a substitute in place
of the value it stores.
What is a variable in C?
l
They must begin with a letter. Some systems permit underscore as the first character.
l
ANSI standard recognizes a length of 31 characters. (In C99, at least 63 characters are
significant.)
l
Uppercase and lowercase are significant. That is, the variable Total is not the same as total
or TOTAL.
l
It should not be a keyword.
l
White space is not allowed.
C Variable Syntax
Here,
data_type: Type of data that a variable can
store.
variable_name: Name of the variable given by
the user.
value: value assigned to the variable by the
user.
Example
int var; // integer variable
Variable Definition
Variable Initialization
1. C Variable Declaration
Example:
int var;
char var2;
3. C Variable Initialization
Local Variables
Global Variables
Static Variables
Automatic Variables
Extern Variables
1. Local Variables in C
Each data type requires different amounts of memory and has some
specific operations which can be performed over it.
The data type is a collection of data with values having fixed values,
meaning as well as its characteristics.
Data Types :
In C programming, data types define the type and size of data that variables can
store.
They specify how much space a variable occupies in memory and the operations
Primary data types are the basic data types provided by C. They
Examples :
Derived data types are derived from the primary data types. They are built upon basic
Examples :
Examples :
time.
constants.
1.Integer Data Type
int var_name;
Example:
Int a=5;
2.Character Data Type
char var_name;
Example:
char a=‘c’;
3. Float Data Type
float var_name;
Example:
float a=2.5
4. Double Data Type
double var_name;
Example
double b = 12.293123;
5.Void Data Type
The void data type in C is used to specify that no value is
present.
void function_name;
Example:
void fun1;
Declaration of variables :
compiler.
l
It tells the compiler what the variable name is.
l
It specifies what type of data the variable will hold.
# Variables in C can not only data type but also storage class that provides information
about their location and visibility.
#The storage class decides the portion of the program within which the variables are
recognized.
/* Example of storage classes */
Int m; #Global Variable or External variable
Main()
{
int i; #Local variables
float balance; #Local variables
….
….
function1();
}
function1()
{
int i; #Local variables
float sum; #Local variables
Defining Symbolic Constants:
Example :