Pps Notes Unit-1
Pps Notes Unit-1
2) Computer Hardware
The hardware component of a computer system consists of 5 parts:
a) Input Device: Usually a keyboard where data is entered into the system. Other examples are
mouse, touch screen, audio input unit etc.
b) Central Processing Unit (CPU): responsible for executing instructions such as arithmetic
calculations, comparisons in data, and movement of data inside the system.
c) Primary Storage: It is also called main memory. It is a place where the programs and data
are stored temporarily during the processing.
d) Output Device: Usually a monitor or a printer to show output. Output shown on a monitor is
known as a soft copy and on a printer is called a hard copy.
e) Auxiliary Storage: It is also known as Secondary storage, used for both input and output. It
is the place where programs and data are stored permanently.
3) Computer Software
It is divided into 2 categories: System software and Application software.
a) System software: It manages the computer resources .It provides the interface between the
hardware and the users. It provides system utilities and other operating services. System
software includes the language translators which convert programs into machine language
for execution, debugging tools to ensure the programs are error free.
b) Application software: It is directly responsible for helping users solve their problems. It can
be used for more than one application, used only for its intended purpose.
4) Computing Environment
a) Personal Computing Environment: If we use a personal computer, we have all the hardware
computing components are tied together in our personal computer.
b) Time Sharing Environment: In the time sharing environment, many users are connected to
one or more computers. These computers may be mini computers or central mainframes. All
Page 1
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
computing is
Page 2
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
done by the central computer. At times it becomes so busy that the computer’s responses become
very slow.
c) Client/Server Environment: This computing environment splits the computing function
between the central computer and users’ computer. The users are given personal workspace and
the central computer is called the server. Work is shared by the computers, thus this environment is
faster and more productive.
d) Distributed Computing: This environment provides a seamless integration of computing
functions between different servers and clients. Eg: ebay uses several computers to provide its
auction service.
5) Computer Languages
To write a program for a computer, we must use a computer language. Over the years
computer languages have evolved from machine languages to natural languages.
1940’s Machine level Languages
1950’s Symbolic Languages
1960’s High-Level Languages
a) Machine Languages: In the earliest days of computers, the only programming languages
available were machine languages. Each computer has its own machine language, which is made of
streams of 0’s and 1’s.
b) Symbolic Languages: These languages used symbols, or mnemonics to represent the
various machine language instructions. As they used symbols, these languages were known as
Symbolic languages. As the computer does not understand this language it must be translated to
machine language, and as they had to be assembled into machine language they soon became known
as Assembly Languages.
c) High Level Languages: The desire to improve programmer efficiency and to change the
focus from the computer to the problem being solved led to the development of high-level language.
They must be converted into machine language. The process of converting them is known as
compilation. C is a high-level language used for system software and new application code.
Page 3
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
the editor, we save our file to the disk. This file will be the input to the compiler. It is known
as a source file.
b) Compiling programs: The code of the source file must be converted into machine language
and this job is done by the compiler. The C compiler is 2 separate programs i.e. the
preprocessor and the translator.
c) Linking programs: A C program is made up of many functions. A few functions are part of
the source file whereas there are other functions which are present elsewhere. The linker
assembles all of these functions into our final executable program.
d) Executing Programs: Once our program has been linked, it is ready for execution. To do this
task we use an Operating System command, such as run. The executable program is read into
the memory by the loader, an OS function. When everything is loaded, the program takes
control and begins execution. Once execution is completed and output is displayed, the OS
removed it from the memory.
7) Algorithms
An algorithm is defined as a procedure or a step by step instruction for solving a problem. They
form the foundation of writing a program.
Characteristics of an Algorithm:-
a) It must have a beginning and an end.
b) Steps must be written in an order.
c) The description of each step must be brief without ambiguity.
d) There should not be any infinite loop.
e) It must provide a complete and perfect solution to the problem.
f) It must be so well written that it takes less memory and less processor time.
Page 4
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
Step 1: Start.
Step 2: Accept r.
Step 3: A=3.14*r*r
Page 6
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
C=2*3.14*r
Step 4: Display A and
C. Step 5: Stop.
8) Flowcharts
A flowchart can be defined as a pictorial diagram representing all the steps of an algorithm. One
gets an overall picture of the logic of the program just by looking at the flowchart.
Symbols:
a) (or)
Page 7
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
A diamond shaped box represents as decision or a condition. The condition is given inside the
box. It has 2 exits, either ‘Yes’ or ‘No’.
e)
A subroutine contains group of statements that are executed when called from main program.
g)
This symbol is used to represent multiple documents or files processed as a part of a task.
i)
Start
Start
Read n
Read a and
Page 8
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
c=a+b NO
n%4=0
Display NO
Yes
Display c
Display “Leap Year”
Stop
INTRODUCTION TO C LANGUAGE
1) History of C programming.
The C programming language is a standard general purpose computer programming
language. It was created about 4 years ago by Dennis Ritchie, in the 1970s and is still widely
influential. It is the first programming language taught to any student learning programming, as it
is a structure-based programming language.
The origin of C is closely tied to the development of UNIX Operating system, originally
implemented in assembly language on PDP 7, later the OS was ported to PDP 11 which is a
version of UNIX, also developed in assembly language.
In 2008, C standards committee published a technical report extending the C language to
address issues providing a common standard for all implementations to adhere to. It includes a
number of features not available in normal C, such as fixed point arithmetic, named address
spaces, and basic I/O hardware addressing.
1960 - ALGOL – International group (Algorithm Language)
1967 – BCPL - Martin Richards (Basic combined programming language)
1970 – B – Ken Thompson
1972 – C – Dennis Ritchie
1983 – ANSI – ANSI committee (American National Standards Institute)
1990 – ISO C – ISO committee (International Organization for Standardization)
1999 - C99 – Standardization committee
Page 9
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
3) C Tokens
In a C program, the smallest individual units are known as C Tokens. C language has six
types of tokens. Programs in C are written using these tokens and the syntax of the language.
The C tokens are:-
● Keywords – float, while etc.
● Constants – 100,-15.4 etc.
● Identifiers – main, amount etc.
● Strings – “ABC”, “computer” etc.
● Operators – +, -, < etc.
● Special symbols – [ ], { } etc.
4) Keywords
All keywords in C have fixed meanings and these meanings cannot be changed. Keywords
can be defined and the baisc building blocks for program statements.
Page 10
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
5) Identifiers
6) Constants
A constant in C language refers to the fixed values that do not change during the execution of
Integer
the program.
Numeric
Real
Constants
Single Character
Character
String
Page 11
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
There are special constants called blackslash character constants. A few examples of
backslash character constants are:-
● \b - backspace
● \n - new line
● \t - horizontal tab
7) Variables
A variable is a named memory location, the value of which can be changed during the
execution of the program. A variable name can be chosen by the programmer in a
meaningful way such that it can reflect its function or nature in the program.
8) Data Types
Data types, in C programming, constitute the characteristics of storage of data elements. They
determine the types of operators or methods of processing data elements.
Page 12
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
Data Types
Primary Data
Types Secondary Data User Defined Data
Types
a) character (char) Types
a) arrays a) Structure (struct)
b) integer (int)
b) pointers b) Union (union)
c) float (float)
c) Enumeration
d) double (double) (enum)
e) void (void)
9) Strings
A string in general can be defined as a series of characters treated as a unit and terminated by
a null character \0.
Page 13
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
Page 14
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
ii) It specifies what type of data or value the variable will hold.
Thus declaration of a variable must be done before they are used in the program.
Primary Type Declaration
Syntax:
data type v1, v2, v3…,
vn; (or)
data type variable name = value;
12) Operators
An Operator is a symbol that tells the computer to perform a certain mathematical or
logical manipulation. Operators are used to manipulate data and variables. The data and
variables which have been manipulated using operators are called Operands.
a) Arithmetic Operators: C provides all the basic arithmetic operators. The Arithmetic operators
are +, -, *, /, % . Arithmetic operators can be performed using 2 operands hence they are binary
in nature.
#include <stdio.h>
void main()
{
int a,b;
printf(“Enter a and b”);
scanf(“%d%d”,&a,&b);
printf(“Sum=%d\nDifference=%d\nproduct=%d\nquotient=%d\nremainder=%d”
Page 15
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
,a+b,a-b,a*b,a/b,a%b);
}
b) Assignment Operators: The operators that are used to assign values are called Assignment
Operators. These operators act as both unary and binary operators. They are =, +=, -=, *= , /=, %=.
Syntax : v op= exp;
Example: x += y+1;
i) a = a+1 i) a+=1
ii) a =a*(n+1) ii) a *= n+1
iii) a = a%b iii) a%=b
iv) a = a / (s+1) iv) a /= s+1
#include <stdio.h>
void main()
{
int a,b;
printf(“Enter a and b”);
scanf(“%d%d”,&a,&b);
printf(“sum=%d”,a+=b);
}
c) Unary Operators: The operators which are used to perform manipulations on a single operand are
called Unary operators. They are of 2 types: Increment and Decrement Operators
● Pre increment Operators: This operator, when used, first increments the value of the operand by
one and then assigns the value to its variable. Example:++i
● Post Increment Operators: This operator, when used, first assigns the value to its variable and
the increments the value of the operand by one. Example:i++
Page 16
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
● Pre Decrement Operators: This operator, when used, first decreases the value of the operand by
one and then assigns the value to its variable. Example: --i
● Post Decrement Operators: This operator, when used, first assigns the value to its variable and
the decreases the value of the operand by one. Example: i - -
#include <stdio.h>
void main()
{
int i, a, b;
printf(“Enter value of i”);
scanf(“%d”,&i);
if(i<10)
{a=++i;
b= i++;
}
else
{ a= - - i;
b= i- -;
}
printf(“%d%d”,a,b);
}
d) Ternary Operators: These are also called Conditional Operators. The ‘?:’ in C allows us to
construct conditional expressions and this operator can be used as an alternative to if else statements.
Syntax: variable name= expression 1? expression 2 : expression 3;
Example: c =(a>b)? a:b; [if false c=0, else c=1]
#include <stdio.h>
void main()
{
int a,b;
printf(“Enter a and b”);
scanf(“%d%d”,&a,&b);
c=(a>b)?a:b;
Page 17
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
printf(“c=%d”,c);
Page 18
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
e) Relational Operators: The relational operators can be used when we wish to compare two quantities
and take decisions based on the results of the comparison. It assigns the value 1 if condiotion is true and
0 if condition is false. The relational operators are:-
#include <stdio.h>
void main()
{
int a, b, c, d, e, f;
printf(“Enter a and b”);
scanf(“%d%d”,&a,&b);
c= (a==b);
d= (a<b);
e= ( a>b);
f= (a!=b); printf(“%d%d%d
%d”,c,d,e,f);
}
f) Logical Operators: In addition to relational operators, C has 3 Logical Operators. They are:-
● && Logical AND
● || Logical OR
● ! Logical NOT
These operators are used when we want to test more than one condition and make decisions.
op-1 op-2 op-1 && op-2 op-1 || op-2 !op-1
Page 19
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
non-zero non-zero 1 1 0
Page 20
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
non-zero 0 0 1 0
0 non-zero 0 1 non zero
0 0 0 0 non zero
#include <stdio.h>
void main()
{
int a, b, c, d, e, f;
printf(“Enter a and b”);
scanf(“%d%d”,&a,&b);
if ( a>10 && b>10)
printf(“BOTH ARE GREATER THAN 10);
else if ( a>10 || b>10)
printf(“ONE OF THE NUMBERS IS GREATER THAN 10);
else
printf(“BOTH ARE NOT GREATER THAN 10”);
}
g) Bit wise Operators: C supports special operators known as bit wise operators for manipulation of
data at bit level. They are not applied to float or double.
Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
<< left shift
>> right shift
~ one's complement
h) Special Operators: These operators which do not fit in any of the above classification are:-
● comma ( , )
● sizeof ( )
● Pointer (*)
● address(&)
Page 21
Dr. Md. Fakhruddin Hasan Nizami Professor, Department of Mechanical Engineering
B.E., M. Tech. (R & A/C), B’Chain & C’Security, Ph.D. Methodist College of Engineering &
Technology
The comma operator is used to link related expressions together, the sizeof operator is used to know the
size of an operand and the address operator is used to find the address of an operand.
14) Expressions
A series of operands and operators which eventually reduce to a single value is called an
expression. For example: 10+15 is an expression whose value is 25. The resultant value can be any type
other than void.
****
Page 22