CSC103-LabSheet 1
CSC103-LabSheet 1
Programming Fundamentals
LAB TASK (CSC103)
PREPARED BY
Abdul Karim Shahid,
Assistant Professor
Create a DOC file to upload your work on turnitin
Title Page:
Lab Work XX
CSC103-Programming Fundamentals
Submitted by:
NAME
FA19-BCS-XXX
B/C
Submitted to:
Mr. Abdul Karim Shahid
Submitted on: September 3, 2019
Problem statement
Flowchart or Pseudo code (if asked)
Solution (C code must contain Your name and registration number)
Screen shot of sample output with white background
Learning Objectives:
1. To make you familiar with the Windows programming environment and the "C"
compiler. For this purpose you will use DevCPP/CodeBlocks/Turbo C (TC). You will
write, compile and run a (it may be your first) programme in "C"
Your lab report is expected to contain the following for each exercise:
One of the common task in every program is the printing of output. We use the output to request input
from a user and later display the status/result, computations etc. In C programming there are several
functions for printing formatted output. Here we discuss the printf() function, which writes output to
the computer monitor. To use the printf() function we must include the stdio library in the source
code. To do this just place the following code at the beginning of your program.
To print a simple message in computer screen you might call printf() function as follows:
#include <stdio.h>
int main()
{
printf ("You are learning printf() function");
return 0;
}
#include <stdio.h>
int main()
{
printf("You are learning printf() function");
printf("You are learning printf() function");
return 0;
}
Output:
You are learning printf() function You are learning printf() function
If we want to print the second output in a new line we must need a different way, which has discussed
in the following section.
Escape sequences in C
An escape sequence is a series of characters that represents a special character. It begins with a
backslash character (\), which indicates that the character(s) that follow the backslash character
should be treated in a special way. C uses escape sequences within a format string to print certain
special characters. For example \n moves the output position to the beginning of the next line. The
following is a list of escape sequences.
\\ prints a backslash
You will get an idea of using the above escape sequences from the following example.
#include<stdio.h>
int main()
{
printf("Create a new line\n");
printf("Print a double quotes (\") within a string\n");
printf("Print a single quotes (\') within a string\n");
printf("Print a Backslash\\ within a string\n");
printf("Using Backspace\b within a string\n");
printf("Using\tTab within a string\n");
return 0;
}
Output:
Exercise 1: Print following shape using simple printf statements (You may print these shapes
vertically in one program)
Exercise 4: Write a C-Program to swap two integer numbers without and with using third
variable.
Start
End