Lab Manual (20EST 102-Programming in C)
Lab Manual (20EST 102-Programming in C)
(Autonomous)
LAB MANUAL
for
Programming in C
(20EST 102)
SAINTGITS COLLEGE OF ENGINEERING
(AUTONOMOUS)
INDEX
Page 1 of 72
SAINTGITS COLLEGE OF ENGINEERING
(AUTONOMOUS)
Expt No : 1
Memory Unit
The I/O Interfaces allow the computer’s memory to receive information and
send data to output devices. They allow the computer to communicate to the
user and to secondary storage devices like disk and tape drives.
Input Devices
Page 3 of 72
SAINTGITS COLLEGE OF ENGINEERING
(AUTONOMOUS)
Output Devices
Memory
Memory is the brain of a computer which stores data and information and
also for retrieving it.
Page 4 of 72
SAINTGITS COLLEGE OF ENGINEERING
(AUTONOMOUS)
RAM memory is large and high ROM is generally small and of low
capacity. capacity.
Costly Cheap
Page 5 of 72
SAINTGITS COLLEGE OF ENGINEERING
(AUTONOMOUS)
Page 7 of 72
SAINTGITS COLLEGE OF ENGINEERING
(AUTONOMOUS)
Expt. No: 2
Aim:
Page 8 of 72
SAINTGITS COLLEGE OF ENGINEERING
(AUTONOMOUS)
pwd
pwd (print working directory) command displays the full pathname of the
current working directory
ls
This command lists the files and folders of a directory.
cd
cd (change directory) command changes the current working directory to
another. You can also use full paths to folders or simply the name of a folder
within the directory you are currently working.
cd <folder name>
cd <full path>
cd ..
change directory one level up.
cd /
Change directory to the root directory
Cd ~
Change to home directory
cp
Copy files or folders
Page 9 of 72
SAINTGITS COLLEGE OF ENGINEERING
(AUTONOMOUS)
mkdir
Make a directory
rm
Remove a directory or files
rm –r
remove a directory with its contents recursively
rmdir
remove an empty directory
man
man command displays a manual page of commands
gedit
Gedit is a commonly used text editor. If gedit is installed, gedit command
will open the text editor application.
Page 10 of 72
SAINTGITS COLLEGE OF ENGINEERING
(AUTONOMOUS)
mv
Move or rename command
Rename example
Move example
sudo
sudo (SuperUser DO) Linux command allows you to run programs or other
commands with administrative privileges. This is useful when, for example,
you need to modify files in a directory that your user wouldn’t normally have
access to.
apt-get
apt-get is used to install, update, upgrade and remove any package. apt-get
basically works on a database of available packages. The list of different apt-
get commands are
Page 11 of 72
SAINTGITS COLLEGE OF ENGINEERING
(AUTONOMOUS)
Step 1: Open a text editor like gedit, make a file with .c extension, type the
program and save in a folder.
Page 12 of 72
SAINTGITS COLLEGE OF ENGINEERING
(AUTONOMOUS)
Step 2: Compile the program using gcc compiler for C and make an
executable file with .out extension with the help of command
gcc <source code filename> -o <output filename>
Step 3: Run the executable code using the following command and verify the
output.
./<output filename>
Result:
Linux environment was familiarized and practiced programming in c with
Linux operating system.
Page 13 of 72
SAINTGITS COLLEGE OF ENGINEERING
(AUTONOMOUS)
Expt No: 3
Algorithm:
i) Step 1: Start
Step 2: Display “Hello World”
Step 3: Stop
ii) Step 1: Start
Step 2: Read two numbers, num1, num2
Step 3: sum = num1 + num2
Step 4: Display sum
Step 5: Stop
iii) Step 1: Start
Step 2: Read a number, radius
Step 3: area = 3.14 x radius x radius
Step 4: Display area
Step 5: Stop
iv) Step 1: Start
Step 2: Read the values of variables a, b, c, d, e, f and g
Step 3: result = ((a -b / c * d + e) * (f +g))
Step 4: Display result
Step 5: Stop
Program - I:
Page 14 of 72
SAINTGITS COLLEGE OF ENGINEERING
(AUTONOMOUS)
Sample Output:
Program - II:
#include<stdio.h>
void main()
Sample Output:
Page 15 of 72
SAINTGITS COLLEGE OF ENGINEERING
(AUTONOMOUS)
Program - III:
#include<stdio.h>
#include<math.h>
void main()
scanf("%f", &radius);
Sample Output:
Program - IV:
#include <stdio.h>
void main()
Page 16 of 72
SAINTGITS COLLEGE OF ENGINEERING
(AUTONOMOUS)
float a, b, c, d, e, f, g, result;
result = ((a-b/c*d+e)*(f+g));
printf("\nResult = %.2f",result);
Result:
The programs to i) Display “Hello World” ii) Read two numbers, add them
and display their sum iii) Read the radius of a circle, calculate its area and
display it iv) Evaluate the arithmetic expression ((a -b / c * d + e) * (f +g)) and
display its solution are executed and outputs are verified.
Page 17 of 72