SPL LAB 1
SPL LAB 1
Page 1
OBJECTIVES
COURSE OUTCOME
After completing this lab course, students will be able to:
To develop the program in a high-level language and translate it into machine level
language following steps have to be practised.
1. Writing and editing the program.
2. Linking the program with the required library modules.
3. Compiling the program.
4. Executing the program.
Page 2
ALGORITHM:-
It is a method of representing the step by step process for solving a problem. Each step
is called an instruction.
Step1: BEGIN
Step2: READ a, b
Step3: ADD a and b and store in variable c
Step4: DISPLAY c
Step5: STOP
CodeBlocks:
CodeBlocks is an IDE (Integrated Development Environment) used to create, edit, compile,
debug and execute C/C++ programs in single place. It is very powerful IDE for developing
C projects. It can be used in both Linux and Windows Operating System.
l e4
Page 3
2.Save the file with .c extention.
3.Write your first code here and then click on “Build and Run” icon.
Page 4
4.Output:
Page 5
STRUCTURE OF a C PROGRAM :
C program is a collection of several instructions where each instruction is written as a
separate statement. The C program starts with a primary function followed by the
opening braces, which indicates the start of the function. Then follows the variable and
constant declarations followed by the statements that include input and output
statements.
DOCUMENTATION SECTION
LINK SECTION
DEFINITION SECTION
GLOBAL DECLARATION SECTION
Main() Function section
{
Declaration part
Executable part
}
SUBPROGRAM SECTION
User defined functions
Page 6
Example:
HEADER FILES
Header files are helping file of your C program which holds the definitions of various
functions and their associated variables that needs to be imported into your C program with
the help of pre-processor #include statement. All the header file have a '.h' an extension that
contains C function declaration and macro definitions. In other words, the header files can be
requested using the preprocessor directive #include. The default header file that comes with
the C compiler is the stdio.h.
Including a header file means that using the content of header file in your source program.
“#include<stdio.h>” is the basic header that must be added to a C program. Other headers
that can be needed are:
abs(),sqrt(),pow(),sin(),cos(),tan(),log(),ceil(),floor(),round() etc.
https://en.cppreference.com/w/c/header
Page 7
KEYWORDS
C has 32 keywords (reserved words with special meaning):
Page 8
OPERATORS
C supports a rich set of operators, which are symbols used within an expression to
specify the manipulations to be performed while evaluating that expression. C has
the following operators:
arithmetic: +, -, *, /, %
assignment: =
augmented assignment: +=, - =, *=, /=, %=, &=, |=, ^=, <<=, >>=
boolean logic: !, &&, ||
equality testing: = =, !=
calling functions: ( )
increment and decrement: ++ and - -
Page 9
INSTRUCTIONS TO STUDENTS FOR PREPARING
PROGRAMMING IN C LAB REPORT
This Lab Manual is prepared to help the students with their practical understanding and
development of programming skills and may be used as a base reference during the
lab/practical classes.
Students have to submit the Lab Exercise report of the previous lab into the
corresponding next lab. It can be collected after the instructor/course teacher has been
checked and signed. At the end of the semester, students should compile all the Lab
Exercise reports into a single report and submit them during the end semester sessional
examination.
“Sample of Lab report” is shown for LAB Exercise #1 in this manual. For the rest of
the labs, the reporting style as provided is to be followed. The lab report to be submitted
during the end semester Sessional Examination should include at least the following
topics:-
1. Top Cover page – pg. 9 (to be used while compiling all the Lab Exercise reports
into single report)
2. Index – pg. 10 (to be used while compiling all the Lab Exercise reports into single
report)
3. Cover page – pg. 11 (to be attached with every Lab Exercise)
4. Title of the program
5. Algorithm (optional)
6. Flowchart (optional)
7. Coding
8. Output (compilation, debugging & testing)
Students are to show the coding and output to the instructor/course teacher for the
additional lab exercises given in each lab module.
Note: The lab exercises may not be completed in a single specific lab. Students are
encouraged to complete the programming questions given in the exercise prior to coming
to the lab hour and do the lab for the given programs.
Page
10
Institute of Information Technology
Jahangirnagar University
SUBMITTED BY
Name:
Class Roll No.
Page 9
INDEX
1. Exercise – 1
(i) Program 1… ......................................................................... 1
(ii) Program 2 ............................................................................. 2
(iii) Program 3, etc.
2. Exercise – 2 ……………………………………………………. ..
3. Exercise – 3 ………………………
4. etc.
5. etc.
Page 10
Institute of Information Technology
Jahangirnagar University
LAB Exercise #1
Name:
Lab Date:
Submission Date:
Page 11
LAB EXERCISE #1
Objective(s):
To be familiar with syntax and structure of C.
To learn problem-solving techniques using C
Program: Write a Program to calculate and display the volume of a CUBE having its
height (h=10cm), width (w=12cm) and depth (8cm).
Algorithm:
1. Start
2. Define variables: h(int), w(int), d(int), vol(int)
3. Assign value to variables: h = 10, w=12, d=8
4. Calculate the volume as: vol = h*w*d
5. Display the volume (vol)
6. Stop
Flowchart:
Page 12
Code: (Use comments wherever applicable)
#include<stdio.h>
void main()
{
//start the program
int h,w,d,vol; //variables declaration
h=10, w=12, d=8; //assign value to variables
vol=h*w*d; //calculation using mathematical formula
printf("The Volume of the cube is: %d",vol); //display the volume
Practice Programs
(Students are to code the following programs in the lab and show the output to
instructor/course teacher)
Instructions
Programs List
1. Write a C program to add two numbers and display its sum.
2. Write a C program the average of three numbers.
3. Write a C program to calculate area of a rectangle.
4. Write a C program to calculate area and circumference of a circle.
5. Write a C program to perform addition, subtraction, division and
multiplication of two numbers.
6. Write C program to evaluate each of the following equations.
(i) V = u + at. (ii) S = ut+1/2a
Page 13