You are on page 1of 5

PC202 - Introduction to Computer Technology-II

Credit:5 (L=4, P=2)


Lab Practical
CC: Nitesh Sureja
Objective:
This is an introductory course for programming language C.
Students are introduced to the basic concepts of solving a problem using C
programming language. Data types available in C, various constructs,
loops, arrays, structures, files, pointers and other important features of C
are covered in depth during the course work. Students are also
encouraged to build their logic for solving related problems using C. This
course provides a platform to learn the higher level languages too.

Lab 1-2 LOOPING


: The C language provides for three loop constructs for performing
loop iterations. They are:
1. The while statement. 2. The do statement. 3. The for statement.
Control structure may be classified as the entry-controlled loop
or as exit-controlled loop.
-The while and for statements are entry-controlled loop
statements.
-The do statement is exit-controlled loop statement.
Exercise:
1 I Write a program to check whether the given
number is prime or not
II Write a program to compute the sum of the digits
of a given integer number.
III Write a program to find the factorial value of a
given number.
IV Write a program to find out the number of digits
of a given number.
2 I Given a number, write a program to reverse the
digits of the number. (For example, the number
12345 should be written as 54321)
II Write a program to print Fibonacci series. The first
seven Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8….
III Write programs to print the following patterns.

a) 1 b) 1 c) 1
d) 1
22 23 2 2
01
333 456 3 3 3
101
4444 7 8 9 10 44 44
0101

Lab3-4 ARRAY:
: An array is a group of related data items that share a
common name. For instance, we can define an array name
salary to represent a set of salaries of a group of employees.
The ability to use a single name to represent a collection of
items and to refer to an item by specifying the item number
enables us to develop concise and efficient programs.
A list of items can be given one variable name using only
one subscript and such a variable is called a single-subscripted
variable or a one-dimensional array.
Exercise:
3: I Write a program to find out maximum and
minimum from 1-D array.
II Write a program to sort an integer array in
ascending order.
III Write a program to sort an integer array in
descending order.
IV Write a programme to print pascal triangle…
V Write a program to search an element in an array, if it is not
there then insert it at the end of the array
4: I Write a program to add two 3 by 3 matrices.
II Write a program to multiply two matrices
III Exercise 7.5 (E Balagurusamy Book, Third
Edition)
Lab 5 STRING.
: A string is an array of characters.
Any group of characters defined between double quotation
marks is a constant string. Character strings are often used to
build meaningful and readable programs. A string variable is any
valid C variable name. The general form of declaration of a string
variable is
Char string_name[ size ];
The size determines the number of characters in the string-
name.
When we initialize a character array by listing its elements, we
must supply explicitly the null terminator.
Exercise:
I Write a separate program that will demonstrate
the use of strcat( ), strcmp( ), strcpy( ), strlen( )
functions.
II Write a program to count the number of words,
number of characters, numbers of blanks and
numbers of lines in a multiline string.
III Write a program to reverse the string.
IV Write a program to count frequency of the last character of a
given string in that string. String will be taken from the user.
Lab 6 USER-DEFINED FUNCTION:
: C functions can be classified into two categories:
1 library functions : example printf, scanf, sqrt etc
2 user-defined functions: main, developed by the user at the
time of writing a program.
A function is a self-contained block of code that performs a
particular task.
In order to make use of a user-defined function, we need to
establish three elements that are related to functions:
1. Function definition
2. Function call
3. Function declaration

Exercise:
I Write a program for addition of two integer
number that will satisfied the following
criteria:
1. Function with no arguments and no return
values.
2. Function with arguments and no return
values.
3. Function with arguments and one return
value.
4. Function with no arguments but return a
value.
II Write a program to find out the factorial of a
given number with the use of recursion.
III Write a program that uses a function to sort
an array of integers.
IV Write a separate program that will demonstrate the use of
static variables and global variables.
Lab7-8 STRUCTURES AND UNIONS:
: An array is a collection of related data elements of same type.
Structure can have elements of different types.
Unions are a concept borrowed from structures and therefore
follow the same syntax as structures. However, there is major
distinction between them in terms of storage. In structures, each
member has its own storage location, whereas all the members
of a union use the same location. This implies that, although a
union may contain many members of different types, It can
handle only one member at a time.
Exercise:
I Define a structure data type called time_struct
containing three members integer hour,
integer minute, and integer second. Develop
a program that would assign values to the
individual members and display the time in
this form: 16:40:51
II Define a structure called cricket that will
describe the following
Information
Player name
Team name
Batting average
Using cricket, declare an array player with 3
elements and write a program to read the
information about all the 3 players and print a
team-wise list containing names of players
with their average.
III Design a structure student_record to contain
name, roll_no,
and total marks obtained. Develop a program
to read data for 10 students in a class and list
them rank-wise.
IV Write a program to demonstrate the use of
union.
Lab 9 POINTERS:
: A pointer is a derived data type in C. Pointers contains memory
addresses as their values. Since these memory addresses are
the locations in the computer memory where program
instructions and data are stored, pointers can be used to access
and manipulate data stored in the memory.
Exercise:
I Write a program using pointers to compute
the sum of all elements stored in an array.
II Write a function using pointers to exchange
the values stored in two locations in the
memory.
III Write a function using pointers for solution of
quadratic equation (ax2+bx+c=0) using
pointers.
Lab10 FILE MANAGEMENT:
: The console oriented I/O functions, such as printf, scanf works
fine as long as the data is small. However, many real-life
problem involve large volumes of data and in such situations,
the console oriented I/O operations pose problems. One of the
problem is the entire data is lost when either the program is
terminated or the computer is turn off.
It is therefore necessary to have a more flexible approach where
data can be stored on the disks and read whenever necessary,
without destroying the data. This method employs the concept of
files to store data. A file is a place on the disk where a group of
related data is stored.
Exercise:
I Write a program to read data from the
keyboard, write it to a file called INPUT, again
read the same data from the INPUT file, and
display it on the screen.
II Write a program to read n integer number
from keyboard and store them into a file
ALL.txt. From the file ALL.txt, separate even
and odd numbers and store them into files
EVEN.txt and ODD.txt respectively.
Display content of all the three files.
III Write a program that will read n number from
keyboard, store them in file UNSORT.txt. Sort
all the contents of UNSORT.txt and store into
SORT.txt.
Display contents of both these files.

You might also like