You are on page 1of 5

EE-133L Programming Fundamentals

Spring 2024

Registration number 2023-EE-421


Name Musa Piracha

Introduction to C Programming
Objective:
1. Understand the basic structure of a C compiler and program.
a) Write a simple program to print text on the screen.

Task 1:
Familiarize yourself with the compiler.

Explanation:
A compiler is a software tool translating high-level source code into machine-readable code. Dev-
C++ is a C and C++ IDE with an integrated compiler. It facilitates writing, compiling, and
debugging within a single application, producing executable files for CPU execution.Some of its
features are:

• User-Friendly Interface
• Fast and Efficient Compilation
• Code Navigation and Editing Features
• Open Source and Free
• Regularly Updated:

In the lab we gained some knowledge about how to use it. We also learned some basics keys
shortcuts like:

• Open File: Ctrl + O


• Save File: Ctrl + S
• Undo: Ctrl + Z
• Redo: Ctrl + Y
• Copy: Ctrl + C
• Paste: Ctrl + V
• Cut: Ctrl + X
• Select All: Ctrl + A
• Compile: F9
• Run: F10

Instructor: Miss Rimsha Chauhdary


EE-133L Programming Fundamentals
Spring 2024

Task 2:
What is basic c-program structure and mention the use of each line.

Code:
1. # include <stdio.h>
2. int main(){
3. return 0;
4. }

Explanation:
The first line, is a preprocessor directive that includes the standard input/output library in
the program. The second line initiates the “main” function. The “main” function is named as
driver function, where execution begins. The third line, “return 0;”statement is used. In C,
returning 0 from “main” typically denotes successful completion. The fourth line contains a closing
bracket, marking the end of the “main” function. This closing brace encapsulates the code.

Task 3:
Print the message "Hello, C Programming!" to the console.

Code:
1. # include <stdio.h>
2. int main(){
3. printf ("Hello, C Programming!");
4. return 0;
5. }

Output:

Explanation:
The provided C code includes a preprocessor directive, essential for the “printf” function.
The “main” function is then defined in line 2, containing a “printf” statement to display message
in line 3 and a “return 0;” statement is used in line 4 signifying successful program execution. The
closing brace (`}`) denotes the end of the “main” function.

Instructor: Miss Rimsha Chauhdary


EE-133L Programming Fundamentals
Spring 2024

Task 4:
Print your name and registration number to the console.

Code:
1. # include <stdio.h>
2. int main(){
i. printf ("Musa Piracha 2023EE421 ");
b. return 0;
3. }

Output:

Explanation:
The provided C code includes a preprocessor directive, essential for the “printf” function.
The “main” function is then defined in line 2, containing a “printf” statement to display my name
and registrations number in line 3 and a “return 0;” statement is used in line 4 signifying successful
program execution. The closing brace (`}`) denotes the end of the “main” function.

Task 5:
Print your name and registration number to the console in the new line.

Code:
1. # include <stdio.h>
2. int main(){
3. printf ("Musa Piracha \n 2023EE421 ");
4. return 0;
5. }

Instructor: Miss Rimsha Chauhdary


EE-133L Programming Fundamentals
Spring 2024

Output:

Explanation:
The provided C code includes a preprocessor directive, essential for the “printf” function.
The “main” function is then defined in line 2, containing a “printf” statement to display my name
and registrations number in line 3 but this time it contains \n which is an escape sequence which
represents the new line it is used to print the data after it in new line. A “return 0;” statement is
used in line 4 signifying successful program execution. The closing brace (`}`) denotes the end of
the “main” function.

Task 6:
Print a string containing special characters (e.g., newline, tab).
Code:
1. # include <stdio.h>
2. int main(){
3. printf ("Mus@\t~\tPir@ch@ \n 2023_EE_421 ");
4. return 0;
5. }

Output:

Explanation:
The provided C code includes a preprocessor directive, essential for the “printf”
function. The “main” function is then defined in line 2, containing a “printf” statement to display

Instructor: Miss Rimsha Chauhdary


EE-133L Programming Fundamentals
Spring 2024

my name and registrations number in line 3 but this time it contains \n which is an escape sequence
which represents the new line it is used to print the data after it in new line. It also contains \t which
is also escape sequence which represents horizontal tab space. It creates a tab space in the output
when the program is executed. A “return 0;” statement is used in line 4 signifying successful
program execution. The closing brace (`}`) denotes the end of the “main” function.

Conclusion:
In this lab, I learned about the introduction of C programming, learned to write the basic
structure of a C program. I also learned about the Compiler which is a software to covert source
code in to machine code. I practiced some basic functions of C programming language and used
them in various tasks that were assigned to me.

Instructor: Miss Rimsha Chauhdary

You might also like