St.

Thomas' College of Engineering and Technology

DEPARTMENT OF COMPUTER SCIENCE AND
ENGINEERING

Laboratory Manual Basic Computation and
Principles of Computer Programming
Code: CS291

Department of Computer Science & Engineering
St. Thomas’ College of Engineering and Technology

Basic Computation &
Name: ____________________________
Course Name Principles of Computer Semester IV
University Roll No: _____________________
Programming
Course Code CS 291
College Year with stream
Roll No: _______________________ 2 year CSE nd

Course Credit 2 Session 2016-17
Year:___________ Semester: _________
Faculty Class hours and
3hrs.
Instructor/sSection: _________ Group:____________
total class load
Technical Session: _____________________________
Laboratory
assistant/s

Course To assist the students to learn C language syntax and handle various problems
objectives with the help of algorithm and C language approaches.

.

At the end of the course, a student will be able to:

Course
Outcomes CO1. Write, compile and debug programs in C language.

CO2. Use different data types, decision structures, loops and functions in a
computer program.

CO3. Understand array, pointers, memory allocation and data handling
through files in ‘C’.

CO4. Understand the working of different operating systems like DOS,
Windows and Linux etc.

Department of Computer Science & Engineering
St. Thomas’ College of Engineering and Technology

Correlation between Course Outcomes (CO) and Program Outcomes (PO)

PO CO

CO 1 CO 2 CO 3 CO 4

PO 1 √ √ √ √

PO 2 √

PO 3 √ v √

PO 4 √

PO 5 √

PO 6 √ √

PO 7

PO 8

PO 9 √ √ √

PO √
10

PO √
11

PO √ √ √ √
12

books 2. 1. 4. Handle any equipment without reading the instructions /Instruction manuals. Late comers without proper reason and permission of HOD will not be allowed to enter the lab. Schied F. 6.W. 2. & Ritchie D. and Shoes). Turn on and off computers properly. the lab faculty will ask the viva Questions and marks are allotted accordingly. Come late in the laboratory. Use Mobile Phones during the lab session. Install any unlicensed software. Kerninghan B. 6. It is mandatory to come with observation book and lab record in which previous experiment should be written in Record and the present lab’s experiment in Observation book. It is mandatory to come to lab in formal dress (College uniform. 4. Department of Computer Science & Engineering St. Strictly observe the instructions given by the Teacher/ Lab Instructor.– Theory and Problems of Computers and Programming. Observation book of the present lab experiment should get corrected on the same day and Record should be corrected on the next scheduled lab session. Prepare for the viva questions.. 3. Gottfried. Do 5.The C Programming Language . 7. Insert pen drive without permission. Do not 5. Thomas’ College of Engineering and Technology Safety Norms and precautions 1.M. Complete the experiment and writing report within the stipulated time 3. Enter the lab without covered shoes 2. At the end of the experiment. Recommended 1.S.Programming with C Schaum. 3. ID card.

Micro project As per policy you have to perform at least one micro project. in which case you may contact your faculty in charge. Plagiarism Collaboration on performing the experiments and taking measurements is strongly encouraged.g. 7. the lab report you hand in must be solely your own.com or any such website.). Department of Computer Science & Engineering St. Experiment in virtual laboratory As per policy you have to perform at least two virtual experiments to be selected from www. . 6. a traffic accident. Calculator policy You may need a calculator device 3. etc. Make-up Experiment Make-up for a missing experiment will not be offered. normally. 2. death in family. . please contact Faculty in charge 5. Sharing written work beforehand is considered as academic dishonesty 4. Thomas’ College of Engineering and Technology Course policies 1. however.vlab. Attendance Attendance is compulsory. Disability Support If you have a disabling condition which may interfere with your ability to successfully complete this module. Cell phones should be turned off and kept out of sight. Please be respectful to your classmates by being on time. The only exceptions to that are illness or emergency (e..

coding. Viva [20%] There is a 10-minute viva-voce during examination time. results and discussion. Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Course assessment process Continuous assessment Lab reports [15%] Experiment number. theory. Objective. Questions and quizzes at the end of each experiment (5%) Assessment during end semester examination Lab examination [40%] Experiments are allotted to the students randomly on lottery basis during examination time which they have to complete within stipulated time. Grading Scale Grade Percent score 0 ≥ 90 E ≥ 80 and <90 A ≥ 70 and <80 B ≥ 60 and <70 C ≥ 50 and <60 D ≥ 40 and <50 F <40 . Lab applications & attendance [20%] Programming performance and lab attendance.

Department of Computer Science & Engineering St. awarded 1 Introduction to C programming in Linux/Unix environment 2 To demonstrate different types of operator 3 To learn control statements in C language 4 To learn loop control statements in C language 5 To learn loop control statements in C language 6 To learn loop control statements in C language 7 To learn about arrays and subscripted variables 8 To learn about arrays and subscripted variables 9 To learn about arrays and subscripted variables 10 To demonstrate the concepts of function 11 To understands of concepts of string manipulations in C . Thomas’ College of Engineering and Technology List of Experiments: Expt. Number Expt. Name of Experiment Page Date of Grade Signature No.

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology 12 To study about structures and unions in C language 13 To gain knowledge about pointers in C language 14 To gain knowledge about file handling in C 15 Beyond syllabus experiment 16 Virtual laboratory experiment 17 Micro Project .

change. changes the shell's current working directory.remove empty directories Syntax: rmdir [OPTION]. vi is used for add. 6.. logout. mv. vi is a text editor. 2.. 2. login.  vi editor. mkdir.. vi can be used from any type of terminal because it does not depend on arrow keys and function keys--it uses the standard alphabetic keys for commands. FILE. DIRECTORY 5.clear the terminal screen Syntax: clear 4. cp. man Short for "manual.make directories Syntax: mkdir [OPTION]. SOURCE. cd: The cd command.move (rename) files syntax: mv [OPTION]. mv . Syntax : man [option(s)] keyword(s) Example: man ls 2. Thomas’ College of Engineering and Technology LAB SESSION 01 Title: Introduction to C programming in Linux/Unix environment Objective: 1. rm.. shutdown. cd . and delete text. Satisfy ____________________________________ knowledge of Bloom’s Taxonomy. 7. To understand input / output functions and statements in C language:-  formatted input / output functions  assignment statements  running a program in Linux/Unix environment 1.... rm . rmdir ... Achieve ___________________of Program Outcomes. To understand basic commands of Linux/Unix:-  man. 3.. cd. which stands for "change directory".remove files or directories Syntax: rm [OPTION]. Theory: 1. but does not provide such formatting capabilities as centering lines or indenting paragraphs. rmdir. Department of Computer Science & Engineering St. ls. Syntax: cd directory Example: cd new cd . This help note explains the basics of vi:  opening and closing a file .. DIRECTORY.. mkdir . DIRECTORY vi editor:- The vi editor is available on Linux/Unix systems.." man helps a user to format and display the user manual built into Linux distributions.. clear ..

mkdir.  Press Shift+: and then :wq or x to save the program  Type cc filename. division. Test the following commands: man. calculate area of the of a triangle. modulus division of the two numbers. Program: . 2. convert degree Fahrenheit to Degree Celsius. calculate the average and deviation of two numbers . rmdir.  Press Esc to exit typing. cd. rm. Write a program in C to read and print your name and values of variables of different data types. shutdown and vi editor in Linux/ Unix environment.c to compile the program  Type /a.c is the file name of the program)  Press Esc+i to insert the program.out to run the program. multiplication. Thomas’ College of Engineering and Technology  moving around in a file  elementary editing Running a program in Linux/Unix environment:- Unix system comprises a C language compiler called cc. login. cp. Write a program to find addition. Department of Computer Science & Engineering St. calculate distance between two points. subtraction. The commonly use editor in Linux/Unix environment is vi editor. ls. ( note that filename.  Type $vi filename. Problem statement: 1. mv. 3. logout. Consider the following steps to run c programs in Linux/Unix operating system.c to invoke the editor.  Enter the c program using keyboard.

Thomas’ College of Engineering and Technology Results and discussions: Questionnaires: . Department of Computer Science & Engineering St.

Thomas’ College of Engineering and Technology Grade awarded: Teacher’s signature with date _______________________ . Department of Computer Science & Engineering St.

less than equal to. greater than. 3. Achieve __________________________ of Program Outcomes. etc.>=. increment and decrement operator. 2. Problem Statement: 1. . ||. Write a program to check whether a given year is leap year or not. bitwise (AND.|. not equal to) operator s.  Bitwise operators: &. XOR. etc. swap two numbers using a temporary variable.  Assignment operator: =. LEFT SHIEFT. 1. greater than equal to.  Etc. Department of Computer Science & Engineering St.  Logical operators: &&.  Increment/ decrement operators: ++/--. equal to. NOT.  Relational operators: <. Write a program to show the use of relational (less than. Satisfy ____________________________________knowledge of Bloom’s Taxonomy. Theory: Different types of operator:-  Arithmetic operators: +. OR. Write a program to calculate the area of the circle. also to swap two numbers without using a temporary variable and print the digit at ones place of a given number. Thomas’ College of Engineering and Technology LAB SESSION 02 Title: To demonstrate different types of operator Objective: To use different types of operator in C language. 2. *. OR. etc. RIGHT SHIEFT) operators. NOT) operators. etc. logical (AND.

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Program: .

Thomas’ College of Engineering and Technology Results and discussions: Questionnaires: . Department of Computer Science & Engineering St.

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Grade awarded: Teacher’s signature with date _______________________ .

50.  determine whether an entered character is a vowel or not using switch statement.  enter the marks of a student in four subjects. aggregate and display the grade obtained by the student.  if-else.  find the greatest of three numbers. iv) If taxable income is above 5. Problem Statement: Writea program to  determine whether a person is eligible for vote or not. . 00. iii) If taxable income is in the range 3. Department of Computer Science & Engineering St.  Nested if.  check whether a number is positive. Calculate the total.00.000 then no tax.  switch.  calculate tax for the following conditions: i) If income is in the range 1. Achieve _____________________________ of Program Outcomes.  find the larger of two numbers.50.00.00.000 – 3. Theory: Different types of control statements are:-  if .001 then charge 30% tax. negative or equal to zero. ii) If taxable income is in the range 1.  determine whether a given character is a vowel or not.000 then charge 10% tax.000 then charge 20% tax. 4. Satisfy ____________________________________knowledge of Bloom’s Taxonomy. Thomas’ College of Engineering and Technology LAB SESSION 03 Title: To learn control statements in C language Objective: To understand basic conditional statements.  find whether the given number is even or odd.  calculate the roots of a quadratic equation. 3.001 – 5.

Thomas’ College of Engineering and Technology  enter a number from 1 to 7 and display the corresponding day of the week using switch statement. Department of Computer Science & Engineering St. Program: .

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Results and discussions: Questionnaires: .

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Grade awarded: Teacher’s signature with date _______________________ .

Thomas’ College of Engineering and Technology LAB SESSION 04 Title: To learn loop control statements in C language Objective: To understand basic loop structures. 5.  display the square and cube of first n natural numbers using do-while loop. Theory: Different types of loop control statements are:-  for loop  while loop  do-while Problem Statement: Write a program to  print 1 to 20 using for. thereby classifying them as even or odd. lower case. and numbers entered by the user. Achieve ___________________________ of Program Outcomes. . while and do-while loop.  calculate the sum of numbers from m to n and also calculate the average of these numbers. Also count the number of upper case.  read the numbers until -1 is encountered. negative and zeros entered by the user. Department of Computer Science & Engineering St.  read the character until a * is encountered. Also count the positive. 6.  print all the numbers from m to n. Satisfy ____________________________________knowledge of Bloom’s Taxonomy.  calculate factorial of a number.

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Program: .

Thomas’ College of Engineering and Technology Results and discussions: Questionnaires: . Department of Computer Science & Engineering St.

Department of Computer Science & Engineering
St. Thomas’ College of Engineering and Technology

Grade awarded:

Teacher’s signature with date _______________________

Department of Computer Science & Engineering
St. Thomas’ College of Engineering and Technology

Department of Computer Science & Engineering
St. Thomas’ College of Engineering and Technology

LAB SESSION 05

Title: To learn loop control statements in C language
Objective: To understand basic loop structures.

7. Satisfy ____________________________________knowledge of Bloom’s Taxonomy.

8. Achieve __________________________ of Program Outcomes.

Theory:
Different types of loop control statements are:-

 for loop
 while loop
 do-while loop
 nested loops

Problem Statement:

1. Write a program to print the following patterns :

***** * 1 0 A 1 1 ***** ** 22 1
2 AB 12 121
***** *** 333 345 ABC 123 1 2 3 2 1 *****
**** 4444 6789 ABCD 1234 1 2 3 4 3 2 1 *****
***** 55555 10 11 12 13 A B C D E 12345 123454321

2. Write a program to generate Pascal’s triangle.

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Program: Results and discussions: .

Thomas’ College of Engineering and Technology Questionnaires: . Department of Computer Science & Engineering St.

Thomas’ College of Engineering and Technology Grade awarded: Teacher’s signature with date _______________________ LAB SESSION 06 . Department of Computer Science & Engineering St.

.  enter a hexadecimal number and display the decimal equivalent of this number.  calculate GCD of two numbers.  read the numbers until -1 is encountered and count the number of prime and composite numbers entered by users.+n/n+1. 10.  calculate xn.Achieve _____________________________ of Program Outcomes.  sum the series ½+2/3+…….  enter a decimal number and display the octal equivalent of this number.  calculate the sum of digits of a given number.  find whether the given number is Armstrong or not. Theory: Different types of loop control statements are:-  for loop  while loop  do-while  nested loops Problem Statement: Write a program to  classify a given number as prime or composite.  enter a binary number and display the decimal equivalent of this number. Department of Computer Science & Engineering St. Satisfy ____________________________________knowledge of Bloom’s Taxonomy. Thomas’ College of Engineering and Technology Title: To learn loop control statements in C language Objective: To understand basic loop structures. Program: . 9.

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Results and discussions: .

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Questionnaires: .

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Grade awarded: Teacher’s signature with date _______________________ LAB SESSION 07 .

Problem Statement: Write a program to  insert a number at a given location in an array.  delete a number from a given location in an array.Achieve _______________________________ of Program Outcomes. Department of Computer Science & Engineering St.  implement linear search. Theory: An array is a collection of similar data elements.  merge two sorted arrays.  merge two unsorted arrays. Thomas’ College of Engineering and Technology Title: To learn about arrays and subscripted variables Objective: To use 1D and 2D arrays in C language. The elements of the array are stored in consecutive memory locations and are referenced by an index (also known as the subscript).  sort n numbers of elements in ascending/descending order using bubble sort. 11. Satisfy ____________________________________knowledge of Bloom’s Taxonomy. Program: . Subscript is an ordinal number which is used to identify an element of the array. 12. These data elements have the same data type.

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Results and discussions: .

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Questionnaires: .

Thomas’ College of Engineering and Technology Grade awarded: Teacher’s signature with date _______________________ LAB SESSION 08 . Department of Computer Science & Engineering St.

Thomas’ College of Engineering and Technology Title: To learn about arrays and subscripted variables Objective: To use 1D and 2D arrays in C language. Program: .  read and display a nxn matrix. These data elements have the same data type. Department of Computer Science & Engineering St. Subscript is an ordinal number which is used to identify an element of the array. The elements of the array are stored in consecutive memory locations and are referenced by an index (also known as the subscript). 2. 14.  sort n numbers of elements in ascending/descending order using selection sort.  implement binary search. Write a program to  sort n numbers of elements in ascending/descending order using insertion sort.Achieve ____________________________ of Program Outcomes. In a class there are 10 students. 13. Write a program using 2D array to print (a) the marks obtained by each student in different subjects (b) total marks and average obtained by each student. Each student is supposed to appear five tests. Theory: An array is a collection of similar data elements. (c) store the average of each student in a separate 1D array so that it can be used to calculate the class average. Satisfy ____________________________________knowledge of Bloom’s Taxonomy. Problem Statement: 1.

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Results and discussions: .

Thomas’ College of Engineering and Technology Questionnaires: . Department of Computer Science & Engineering St.

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Grade awarded: Teacher’s signature with date _______________________ LAB SESSION 09 .

Problem Statement: 1. Theory: An array is a collection of similar data elements. . The elements of the array are stored in consecutive memory locations and are referenced by an index (also known as the subscript).Achieve _________________________ of Program Outcomes. Write a program to  input two mxn matrices and then calculate the addition. 16. subtraction and multiplication. Satisfy ____________________________________knowledge of Bloom’s Taxonomy. Subscript is an ordinal number which is used to identify an element of the array.  transpose a 3x3 matrix. Department of Computer Science & Engineering St. 15. These data elements have the same data type. Thomas’ College of Engineering and Technology Title: To learn about arrays and subscripted variables Objective: To use 1D and 2D arrays in C language.

Thomas’ College of Engineering and Technology Program: . Department of Computer Science & Engineering St.

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Results and discussions: Questionnaires: .

Thomas’ College of Engineering and Technology Grade awarded: Teacher’s signature with date _______________________ LAB SESSION 10 Title: To demonstrate the concepts of function Objective: how to solve problems using function in C language. . Department of Computer Science & Engineering St.

Department of Computer Science & Engineering St. Write a program to check a number is prime or not using function with four categorized: (i) function with no argument passing and no return value (ii) function with no argument passing and return value (iii) function with argument passing and no return value (iv) function with argument passing and return value 3.  calculate the area of the circle using function. 2. Thomas’ College of Engineering and Technology 17.  calculate (P(n/r)). Write a program to  find the maximum between two numbers using function. 18. Theory: Different types of functions:-  User defined function  Library function  Recursive function Problem Statement: 1. Write a recursive program in C to  find factorial of a given number  find xn  display the first n terms of the Fibonacci series.  Solve Tower of Hanoi problem Program: . Satisfy ____________________________________knowledge of Bloom’s Taxonomy.Achieve ___________________________ of Program Outcomes.

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Results and discussions: .

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Questionnaires: .

Thomas’ College of Engineering and Technology Grade awarded: Teacher’s signature with date _______________________ LAB SESSION 11 . Department of Computer Science & Engineering St.

Problem Statement: 1. Theory: Different types of string handling functions:-  strlen()  strcpy()  strcat()  strcmp()  etc. Thomas’ College of Engineering and Technology Title: To understands of concepts of string manipulations in C Objective: To use different types of string handling in-built and user defined functions 19.  Test whether a given string is a palindrome string or not. Satisfy ____________________________________knowledge of Bloom’s Taxonomy. 20. .  count the number of vowels and consonants of a given sentence.  Concatenate and compare two strings  Convert a line in the lower case text to upper case and vice-versa.Achieve ____________________ of Program Outcomes. Department of Computer Science & Engineering St. Write a program to  count the occurrence of a particular character in the given string.

Thomas’ College of Engineering and Technology Program: . Department of Computer Science & Engineering St.

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Results and discussions: Questionnaires: .

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Grade awarded: Teacher’s signature with date _______________________ LAB SESSION 12 .

union tag_name { type data_member1. 21. . type data_member2. Satisfy ____________________________________knowledge of Bloom’s Taxonomy. A structure has the following general form: struct tag_name { type data_member1. It has the folling form. } where type is the data type of data members. Union: Similar to a structure. 22. a union also consists of data members but only one data member is active at a time. …………………… type data_memberN. …………………… type data_memberN. Theory: Structure: A structure is a user defined compound data type which consists of data members related to a person or an item. type data_member2. } where type is the data type of data members. Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Title: To study about structures and unions in C language Objective: To learn the concepts of structure and union variables and arrays.Achieve ________________________ of Program Outcomes.

insert programs on unions……………………………………………………………………. The program should output the marks of a specified student given his/ her roll number. Program: . name and total marks of a student. Write a program to input information about n students in a class given the following: roll number. Define a structure with the three members: roll number.. 3. Thomas’ College of Engineering and Technology Problem Statement: 1. Write a C program to read and display the details of a student. 2. name and total marks. Department of Computer Science & Engineering St.

Thomas’ College of Engineering and Technology Results and discussions: . Department of Computer Science & Engineering St.

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Questionnaires: .

Thomas’ College of Engineering and Technology Grade awarded: Teacher’s signature with date _______________________ LAB SESSION 13 Title: To gain knowledge about pointers in C language Objective: To understands the concepts of pointer variables in C. . Department of Computer Science & Engineering St.

Problem Statement: Write a program to  find the sum of two values using pointer. Thomas’ College of Engineering and Technology 23. 24. Satisfy ____________________________________knowledge of Bloom’s Taxonomy.  find the biggest of three numbers using pointer. Program: . The general syntax of pointer variables: data_type *ptr_name.  input two mxn matrices and then calculate the sum of two matrices using dynamic memory allocation.  Swap values of two integer variables using call by reference.Achieve ___________________________ of Program Outcomes.  print all even number from m to n using pointer. Department of Computer Science & Engineering St. Theory: A pointer is a variable that stores the address of another variable.

Thomas’ College of Engineering and Technology Results and discussions: . Department of Computer Science & Engineering St.

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology Questionnaires: .

write. read. close etc. Department of Computer Science & Engineering St. . Thomas’ College of Engineering and Technology Grade awarded: Teacher’s signature with date _______________________ LAB SESSION 14 Title: To gain knowledge about file handling in C Objective: To learn about file open.

Achieve ___________________________ of Program Outcomes. Problem Statement: Write a program to  create a text file and read this text file and count the number of vowels and consonants in this file. Satisfy ____________________________________knowledge of Bloom’s Taxonomy.  Copy the contents of one file to another. Department of Computer Science & Engineering St. Program: . 26. Thomas’ College of Engineering and Technology 25.

Thomas’ College of Engineering and Technology Results and discussions: Questionnaires: . Department of Computer Science & Engineering St.

Department of Computer Science & Engineering St. Thomas’ College of Engineering and Technology .

Thomas’ College of Engineering and Technology Grade awarded: Teacher’s signature with date _______________________ . Department of Computer Science & Engineering St.