PPSL Lab manual Pr 1-3
PPSL Lab manual Pr 1-3
LAB MANUAL
Programming for Problem Solving Lab (N-ESC102P)
Year: 1st
Semester: I
Name of Student:
Roll No.:
Semester/Year:
Academic Session:
Date of Performance:
Date of Submission:
Hardware Requirement
● Processor : Dual Core
● RAM : 1GB
● Hard Disk Drive : > 80 GB
Software Requirement
● Operating System – Windows 2007 and Ubuntu
● Package used – gcc/g++
● IDE - TURBO C++, DEV C++
DO’S
● Students should enter into the Laboratory with prior permission.
● Students should come in proper uniforms.
● Students should come with Practical note book to the laboratory.
● Students should maintain silence inside the laboratory.
● After completing the laboratory exercise, make sure to shut down the system and arrange
chairs properly.
DONT’S
● Students bringing the bags inside the laboratory.
● Students using mobile phones inside the laboratory.
● Students using the computers in an improper way.
● Students scribbling on the desk and mishandling the chairs.
● Students making noise inside the laboratory.
List of Practicals
Name of Lab Course: Programming for Problem Solving (N-ESC102P)
Sr.
Name of Practical CO
No.
PRE-LAB SESSION: To work with computer systems, various operating systems and
0 --
installation of various C language IDEs.
Construct a C program to demonstrate the working of various operators.
a. Construct a C program to perform an arithmetical operation by using the
assignment operator.
1 CO1
b. Construct a C program that compares two numbers using various relational
operators.
PRE-LAB
AIM: To work with computer system, various operating system and
installation of various C language IDEs.
Name of Student:
Roll No.:
Semester/Year:
Academic Session:
Date of Performance:
Date of Submission:
AIM: To work with computer system, various operating system and installation of various c
language IDEs.
THEORY:
Computer
A computer is a machine that can be programmed to carry out sequences of arithmetic or logical
operations automatically.
The brain of a computer is CPU. It has three components- Memory unit, Control unit and
Arithmetic and Logical unit (ALU)- Memory unit also called storage device is to store information.
Two types of memory are there in a computer. They are RAM (random access memory) and ROM
(read only memory). When a program is called, it is loaded and processed in RAM. When the
computer is switched off, whatever stored in RAM will be deleted. So, it is a temporary memory.
Whereas ROM is a permanent memory, where data, program etc are stored for future use. Inside
a computer there is a storage device called Hard disk, where data are stored and can be accessed
at any time.
The control unit is for controlling the execution and interpreting of instructions stored in
the memory. ALU is the unit where the arithmetic and logical operations are performed. The
Physical components of a computer are called hard wares. But for the machine to work it requires
certain programs (A set of instructions is called a program). They are called soft wares. There are
two types of soft wares – System software and Application software.
All general-purpose computers require the following hardware components:
● Memory: Memory enables a computer to store, at least temporarily, data and programs.
● Mass storage device: This allows a computer to permanently retain large amounts of data.
Common mass storage devices include solid state drives (SSDs) or disk drives and tape drives.
● Input device: Usually a keyboard and mouse, the input device is the conduit through which
data and instructions enter a computer.
● Output device: An output device is a display screen, printer, or other device that lets you
see what the computer has accomplished.
● Central processing unit (CPU): The heart of the computer, this is the component that
actually executes instructions.
● A motherboard: This component allows all of the other components to communicate with
one another.
Operating Systems
The set of instructions which resides in the computer and governs the system are called operating
systems, without which the machine will never function. They are the medium of communication
between a computer and the user. DOS, Windows, Linux, Unix etc are Operating Systems.
reside on one computer. if you have a primary operating system and an alternate system that you
use less frequently. Another reason for multi-booting can be to investigate or test a new operating
system without switching completely.
Windows:
Microsoft Windows has existed in one form or another since 1985, and it remains the most popular
operating system for home and office computers. Computers from a wide variety of manufacturers can
use Windows. Initial versions of Windows worked with an earlier Microsoft operating system called
MS-DOS, providing a modern graphical interface on top of DOS's traditional text-based commands.
Signature features of Microsoft Windows's user interface include windows themselves – rectangle-
shaped, on-panel screens that represent individual applications. The Windows Start menu has helped
generations of users find programs and files on their devices.
Linux:
Linux is an open source operating system (OS). An operating system is the software that directly
manages a system's hardware and resources, like CPU, memory, and storage. The OS sits between
applications and hardware and makes the connections between all of your software and the
physical resources that do the work. Linux terminal is a user-friendly terminal as it provides
various support options. To open the Linux terminal, press "CTRL + ALT + T" keys together, and
execute a command by pressing the 'ENTER' key.
Computer Languages
Languages are a means of communication. Normally people interact with each other through a
language. On the same pattern, communication with computers is carried out through a language.
This language is understood both by user and the machine. Just as every language like English,
Hindi has its grammatical rules; every computer language is bound by rules known as SYNTAX
of that language. The user is bound by that syntax while communicating with the computer system.
The software (set of programs) that reads a program written in high level language and
translates it into an equivalent program in machine language is called as Compiler. The program
written by the programmer in high level language is called source program and the program
generated by the compiler after translation is called as object program.
IDEs
An integrated development environment (IDE) is a software application that provides
comprehensive facilities to computer programmers for software development. It helps a
programmer to program easily by providing all the comprehensive facilities required for the
development of software. IDE can improve the productivity of a programmer or developer because
of its fast setup and various tools. Without this, a programmer takes a lot of time deciding on
various tools to use for their tasks.
Mainly, an IDE includes 3 parts i.e. source code editor, a build automation tool
(compiler), and a debugger. The source code editor is something where programmers can write the
code, whereas, build automation tool is used by the programmers for compiling the codes and the
debugger is used to test or debug the program in order to resolve any errors in the code.
Installation of IDEs
Dev C++
Step 1: First you must download the Dev C++ on your Windows machine. Visit to Download
Dev C++: https://sourceforge.net/projects/orwelldevcpp/
Step 2: This package will download C++ .exe file for Windows that can be used to install on
Windows 7/8/XP/Vista/10.
Step 3: Double click the executable file.
Step 4: The installer will ask you a language to select. Select “English” and click on “OK”.
Step 5: Then screen for license agreement will appear. Click on “I agree” to proceed further.
Step 6: You can see different components of Dev C++ that will be installed with this package.
Just click on “next” button.
Step 7: By default, the destination folder is in C drive. You are free to change this destination
folder but make sure you have enough memory. Click on “Install” button.
Step 8: In the next screen, installation begins.
Step 9: Now, Dev C++ is installed successfully on your Windows. Select “Run Dev C++” to run
it and click on “Finish” button.
Step 10:That’s it! Now you are ready to compile your C or C++ programs with Dev C++ compiler.
Turbo C++
Step 1: First you must download the Dev C++ on your Windows machine. Visit to Download Dev
C++: https://developerinsider.co/download-turbo-c-for-windows-7-8-8-1-and-windows-10- 32-
64-bit-full-screen/
Step 2: Now, you need to create a new directory turbo c inside the c: drive. Now extract the zip
file in c:\turboc directory.
Step 3: Double click on the install.exe file and follow steps. Now, click on the install icon located
inside the c:\turboc.
Step 4: Click on next.
Step 5: In the next screen, installation begins.
Step 6: After installation click on next, then click on finish.
Step 7: Now it will be showing console.
CONCLUSION: Hence we have studied about computer system, operating system and
installation of various C language IDEs.
REFERENCE:
● https://www.youtube.com/watch?v=rRSD128KWIM
● https://www.youtube.com/watch?v=g3GUnBZEPwQ
● https://en.wikipedia.org/wiki/Computer
● https://www.webopedia.com/definitions/computer/
● https://sourceforge.net/projects/orwelldevcpp/
Name of Student:
Roll No.:
Semester/Year:
Academic Session:
Date of Performance:
Date of Submission:
b. Construct a C program that compares two numbers using various relational operators
THEORY:
Operator is a symbol that tells the compiler to perform specific mathematical, conditional, or
logical functions. It is a symbol that operates on a value or a variable. For example, + and - are the
operators to perform addition and subtraction in any C program.
Types of Operators in C
1. Arithmetic operators
2. Assignment operators
3. Relational operators
4. Logical operators
5. Bit wise operators
6. Conditional operators (ternary operators)
7. Increment/decrement operators
8. Special operators
1. Arithmetic Operators
C Arithmetic operators are used to perform mathematical calculations like addition, subtraction,
multiplication, division and modulus in C programs. Assume variable A holds 10 and variable B
holds 20 then.
Operator Description Example
2. Assignment Operators
In C programs, values for the variables are assigned using assignment operators. For example, if
the value “10″ is to be assigned for the variable “sum”, it can be assigned as “sum = 10;” Other
assignment operators in C language are given below.
Operator Description Example
3. Relational Operators
The following table shows all the relational operators supported by C. Assume variable A holds 10
and variable B holds 20 then −
Operator Description Example
Checks if the values of two operands are equal or not. If yes, then the (A == B)
== condition becomes true. is not true.
Checks if the values of two operands are equal or not. If the values are not (A != B) is
!= equal, then the condition becomes true. true.
Checks if the value of left operand is greater than the value of right (A > B) is
> operand. If yes, then the condition becomes true. not true.
Checks if the value of left operand is less than the value of right operand. (A < B) is
< If yes, then the condition becomes true. true.
Checks if the value of left operand is greater than or equal to the value of (A >= B)
>= right operand. If yes, then the condition becomes true. is not true.
Checks if the value of left operand is less than or equal to the value of (A <= B)
<= right operand. If yes, then the condition becomes true. is true.
4. Logical Operators
These operators are used to perform logical operations on the given expressions. o There are 3
logical operators in C language. They are, logical AND (&&), logical OR (||) and logical NOT (!).
Assume variable A holds 1 and variable B holds 0, then −
Operator Description Example
Called Logical AND operator. If both the operands are non-zero, then the (A && B)
&& condition becomes true. is false.
Called Logical OR Operator. If any of the two operands is non-zero, then (A || B) is
|| the condition becomes true. true.
Called Logical NOT Operator. It is used to reverse the logical state of its
operand. If a condition is true, then Logical NOT operator will make it false. !(A &&
!
B) is true.
5. Bitwise Operators
These operators are used to perform bit operations. Decimal values are converted into binary values
which are the sequence of bits and bit wise operators work on these bits. o Bit wise operators in C
language are & (bitwise AND), | (bitwise OR), ~ (bitwise OR), ^ (XOR), << (left shift) and >>
(right shift). The truth tables for &, |, and ^ is as follows –
p q p&q p|q p^q
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1
Binary AND Operator copies a bit to the result if it exists in (A & B) = 12, i.e.,
& both operands. 0000 1100
(A | B) = 61, i.e.,
| Binary OR Operator copies a bit if it exists in either operand. 0011 1101
Binary XOR Operator copies the bit if it is set in one operand (A ^ B) = 49, i.e.,
^ but not both. 0011 0001
Binary One's Complement Operator is unary and has the effect (~A ) = ~(60), i.e,.
~ of 'flipping' bits. -0111101
Binary Left Shift Operator. The left operands value is moved A << 2 = 240 i.e.,
<< left by the number of bits specified by the right operand. 1111 0000
Binary Right Shift Operator. The left operands value is moved A >> 2 = 15 i.e.,
>> right by the number of bits specified by the right operand. 0000 1111
7. Increment/decrement Operators
Increment operators are used to increase the value of the variable by one and decrement
operators are used to decrease the value of the variable by one in C programs.
Syntax:
8. Special Operators
Besides the operators discussed above, there are a few other important operators
including sizeof and ? : supported by the C Language.
sizeof() Returns the size of a variable. sizeof(a), where a is integer, will return 4.
CODE:
2.
3.
b. Construct a C program that compares two numbers using various relational operators
CODE:
2.
3.
CONCLUSION: Hence, we understood the concept of operators in C programming language and have
written a c program to demonstrate the working of operators.
REFERENCE:
● https://www.youtube.com/watch?v=d5cLIiTSoTA
● https://www.programiz.com/c-programming/c-operators
● https://www.geeksforgeeks.org/operators-in-c/
Name of Student:
Roll No.:
Semester/Year:
Academic Session:
Date of Performance:
Date of Submission:
THEORY:
Decision making structures require that the programmer specifies one or more conditions to be
evaluated or tested by the program, along with a statement or statements to be executed if the
condition is determined to be true, and optionally, other statements to be executed if the condition
is determined to be false. Show below is the general form of a typical decision making structure
found in the programming languages –
C programming language assumes any non-zero and non-null values as true, and if it is either zero
or null, then it is assumed as false value.
C programming language provides the following types of decision making statements.
Decision-making statements:
1. if statement – An if statement consists of a Boolean expression followed by one or
more statements.
Syntax:- if(condition)
{
True Statement;
}
{
True Statement;
}
else {
False Statement;
3. nested if statements: You can use one if or else if statement inside another if or else if
statement(s).
Syntax:- if(condn1){
if(condn2){
Statement;
}
else {
Statement;
}
}
CODE:
2.
3.
b. Write a c program to check whether a number is even positive, odd positive or negative.
ALGORITHM / FLOWCHART:
CODE:
2.
3.
REFERENCE:
● “Programming in ANSI C” by balaguruswamy 7th edition
● https://www.youtube.com/watch?v=aG7J3m3vlNA
● https://en.wikipedia.org/wiki/Prime_number
● https://www.tutorialspoint.com/cprogramming/c_decision_making.htm
Name of Student:
Roll No.:
Semester/Year:
Academic Session:
Date of Performance:
Date of Submission:
THEORY:
CONTROL FLOW STATEMENTS
1. The while Statement
The while statement is a simple way to repeatedly execute one or more statements as long as some
condition is "true".
Syntax:
while (expression) statement;
Firstly, expression is evaluated.
If it is false, statement is not executed and control passes to the next program instruction.
If it is true, statement is executed, then expression re-evaluated to decide if statement should be executed
again.
Example: i=0;
while (numbers[i]!=0)
i++;
In the above examples the statement following the while condition is simply a blank. ie. it does nothing
when it is executed. However, each time the program goes round the loop the variable i is executed as
there is an embedded i++ statement inside the condition that is evaluated.
Note that the statement(s) following the condition in a while loop may never be executed if expression
evaluates to "false" the first time, but if there is a statement embedded in the loop it is executed at least
once while the program decides whether it is true or false.
Once again, braces can be used to form a compound statement if more then one statement is to be
executed, repeatedly
Example: total=i=0;
while (numbers[i]!=0) {
total+=numbers[i];
i++;
}
Example: total=0;
for (i=0; i<10; i++)
total+=numbers[i];
expression1, expression2, expression3 are all optional. If not present expression1 and expression3 are
treated as blank statements and the condition, expression2 is considered to be always true.
ALGORITHM / FLOWCHART:
CODE:
2.
3.
ALGORITHM / FLOWCHART:
CODE:
2.
3.
REFERENCE:
● https://www.studocu.com/in/document/kalinga-institute-of-industrial-
technology/programming-in-c/c-programming-viva-questions/29118795
● https://intellipaat.com/blog/tutorial/c-tutorial/c-loops/
● https://www.youtube.com/watch?v=irqbmMNs2Bo