Lab-Sheet - 1
Lab-Sheet - 1
C Language Basics d) Now you are ready to write your first program in C. Type the
following code:
1.1 Objectives
/* Hello World */
1. To get acquainted with the programming editor or the
#include <stdio.h>
Code::Blocks Integrated Development Environment (IDE).
int main() {
2. To learn the basics of program coding, compilation, run and
printf("Welcome to the programming world !\n");
the usage of printf() and scanf().
return(0);
Time-span: Two lab days (4 hrs)
}
1.2 Instruction:
e) To compile your program, use the following command in the
We prefer to use either a plain text editor or Code::Blocks1 IDE to terminal. (You might need to open another instance of
write the computer programs in C. You might have other options as terminal.)
well.
$gcc <your_program.c> -o your_program
1.2.1 Using a text editor: gedit
f) To run your program, use the following command in the
a) Create a folder where you want to place your C program terminal.
source, you can use mkdir <folder_name> command to do
$./your_program
so.
1 https://www.codeblocks.org/downloads/
Everest Engineering College Page 1|5 Everest Engineering College Page 2|5
Lab Sheet -1: C Programming Basics Santa Basnet Lab Sheet -1: C Programming Basics Santa Basnet
c) Go to File => New => File => C/C++ Source and give use of escape sequences, the escape sequences in C are “\
name <your_program.c>. n”, “\t”, “\\” etc.
d) Type the following code: b. Calculate the mass of air in an automobile tyre, using the
formula:
/* Hello World */
PV = 0.37m(T+460)
#include <stdio.h>
where P is the air pressure in the tyre (pounds per square
int main() {
inch), V is the volume (in cubic feet), m is the mass of air (in
printf("Welcome to the programming world !\n");
pounds), T is the temperature in Fahrenheit.
return(0);
Note: Algorithm and Flowchart needed.
}
c. Write a program that reads the name of the user and greets
him/her. Refer the following sample output.
e) Save your code with Save file option in file menu Or you
Enter your name: Ramesh
can use Ctrl + S shortcut to save your new changes in the
Hello Ramesh! Welcome to the world of programming.
source file.
f) To compile your program, select Compile current file Note: The students should make a list of syntax errors that may
option from the Build menu. It will show errors if you write occur while attempting the programming problems and mention
incorrect syntax or some warning in many cases. You can why each of those errors occurred.
press Shift + Ctrl + F9 for shortcut to compile the source
1.4 Format of the Lab Report
file.
You need to submit the report of the laboratory work after
g) To run your program: select Run from Build menu. It will
completion of each sheet. The report should have a cover page
display your program output. You can press Ctrl + F10 for
mentioning:
shortcut.
(i) Your name and Class Roll Number,
1.3 Problems
(ii) Lab sheet title and problem.
a. Use the printf() function for drawing (a) a house, (b) a tree
The body of the report should include the following components for
and (c) any figure from your imagination. Make appropriate
each problem.
Everest Engineering College Page 3|5 Everest Engineering College Page 4|5
Lab Sheet -1: C Programming Basics Santa Basnet
1. The question.
2. Flowchart and algorithm (only for the questions which
explicitly asks to give flowchart/algorithm).
3. Properly commented and well-structured source code.