0% found this document useful (0 votes)
6 views10 pages

C Lab Manual 2023

The document is a lab manual for the CS3271 Programming in C course at Theni Kammavar Sangam College of Technology. It outlines course objectives, a list of experiments, and expected outcomes for students, focusing on various C programming constructs including I/O statements, decision-making, loops, arrays, strings, functions, recursion, pointers, structures, and file handling. Additionally, it provides sample programs and exercises for practical implementation of these concepts.

Uploaded by

santhikala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views10 pages

C Lab Manual 2023

The document is a lab manual for the CS3271 Programming in C course at Theni Kammavar Sangam College of Technology. It outlines course objectives, a list of experiments, and expected outcomes for students, focusing on various C programming constructs including I/O statements, decision-making, loops, arrays, strings, functions, recursion, pointers, structures, and file handling. Additionally, it provides sample programs and exercises for practical implementation of these concepts.

Uploaded by

santhikala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

THENI KAMMAVAR SANGAM COLLEGE OF TECHNOLOGY

KODUVILARPATTI, THENI – 625 534

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CS3271

PROGRAMMING IN C

LAB MNUAL

(Regulation 2021)
CS3271 PROGRAMMING IN C LABORATORY LTPC
0042
COURSE OBJECTIVES:
 To familiarize with C programming constructs.
 To develop programs in C using basic constructs.
 To develop programs in C using arrays.
 To develop applications in C using strings, pointers, functions.
 To develop applications in C using structures.
 To develop applications in C using file processing.

LIST OF EXPERIMENTS:
Note: The lab instructor is expected to design problems based on the topics listed. The
Examination shall not be restricted to the sample experiments designed.
1. I/O statements, operators, expressions
2. Decision-making constructs: if-else, go to, switch-case, break-continue
3. Loops: for, while, do-while
4. Arrays: 1D and 2D, multi-dimensional arrays, traversal
5. Strings: operations
6. Functions: call, return, passing parameters by (value, reference), passing arrays to
function.
7. Recursion
8. Pointers: Pointers to functions, Arrays, Strings, Pointers to Pointers, Array of Pointers
9. Structures: Nested Structures, Pointers to Structures, Arrays of Structures and Unions.
10. Files: reading and writing, File pointers, file operations, random access, processor
directives.
TOTAL: 60
PERIODS
COURSE OUTCOMES:
Upon completion of the course, the students will be able to
CO1: Demonstrate knowledge on C programming constructs.
CO2: Develop programs in C using basic constructs.
CO3: Develop programs in C using arrays.
CO4: Develop applications in C using strings, pointers, functions.
CO5: Develop applications in C using structures.
CO6: Develop applications in C using file processing.

TEXT BOOKS:
1. ReemaThareja, “Programming in C”, Oxford University Press, Second Edition, 2016.
2. Kernighan, B.W and Ritchie,D.M, “The C Programming language”, Second Edition,
Pearson Education, 2015.

REFERENCES:
1. Paul Deitel and Harvey Deitel, “C How to Program with an Introduction to C++”, Eighth
edition, Pearson Education, 2018.
2. Yashwant Kanetkar, Let us C, 17th Edition, BPB Publications, 2020.
3. Byron S. Gottfried, "Schaum's Outline of Theory and Problems of Programming with C",
McGraw-Hill Education, 1996.
4. Pradip Dey, Manas Ghosh, “Computer Fundamentals and Programming in C”, Second
5. Edition, Oxford University Press, 2013.
6. Anita Goel and Ajay Mittal, “Computer Fundamentals and Programming in C”, 1st
Edition, Pearson Education, 2013.
Page No.
S. No. Name of the Experiment
I/O STATEMENTS, OPERATORS, EXPRESSIONS.
1a. Write a C program to swap values of two variables with and without using
third variable.
1b. Write a C program to take input of name, roll no and marks obtained by a
student in 4 subjects of 100 marks each and display the name, roll no with
percentage score secured.
1c. Write a C program to calculate area and circumference of a circle.
DECISION-MAKING CONSTRUCTS: IF-ELSE, GO TO, SWITCH-CASE, BREAK-
CONTINUE
2a. Write a C program to input two numbers and display the maximum number
using if-else.
2b. Write a C program to find whether a character is consonant or vowel using
switch statement.
2c. Illustrate jumping statements in C
LOOPS: FOR, WHILE, DO-WHILE
3a. Write a C program to check whether a number is Palindrome or not - (for
loop).
3b. Write a C program to find the factorial of a number - (While loop).

3c.
Write a C program to print positive integers from 1 to 10 - (do-While loop).
ARRAYS: 1D AND 2D, MULTI-DIMENSIONAL ARRAYS, TRAVERSAL
4a. Write a C program to insert 5 elements into an array and print the elements of
the array.
4b. Write a C Program to access an element in 2-D Array
4c.
Write a C Program to multiply two 3 X 3 Matrices
STRINGS: OPERATIONS
5a.
Write a C program to concatenate two strings.
5b. Write a C program to compare two strings without using string library
functions.
5c. Write a C program in C to copy one string to another string.

FUNCTIONS: CALL, RETURN, PASSING PARAMETERS BY (VALUE, REFERENCE),


PASSING ARRAYS TO FUNCTION.
6a. Write a C program to swap two integers using call by value and call by
reference methods of passing arguments to a function
6b. Write a C program to add, subtract, multiply and divide two integers using
user defined type function with return type
6c. Write a C program to swap two integers using call by value and call by
reference methods of passing arguments to a function.
RECURSION
7a.
Write a C program to generate Fibonacci series using recursive function
7b.
Write a C program to find power of any number using recursion.
7c.
Write a C program to find the factorial the given number.
POINTERS: POINTERS TO FUNCTIONS, ARRAYS, STRINGS, POINTERS TO
POINTERS, ARRAY OF POINTERS
8a.
Write a C program to find biggest among three numbers using pointer
8b.
Write a C program to compare two strings using pointers.
8c. Write a C program to search an element in array using pointers.
STRUCTURES: NESTED STRUCTURES, POINTERS TO STRUCTURES, ARRAYS OF
STRUCTURES AND UNIONS.
9a. Write a C program to create, declare and initialize structure
9b. Write a C program to store information of 5 students in structure and display it
9c.
Write a C program to declare, initialize an UNION
FILES: READING AND WRITING, FILE POINTERS, FILE OPERATIONS, RANDOM
ACCESS, PROCESSOR DIRECTIVES.
10a. Write a C program to create a file called emp.rec and store information about a
person, in terms of his name, age and salary.
10b. Write a C program to list all files and sub-directories in a directory
10c.
Write a C Program to print contents of file

I/O STATEMENTS, OPERATORS, EXPRESSIONS.


Ex No: 1a

Write a C program to swap values of two variables with and without using third variable.

Program:

Using third variable:

#include<stdio.h>
int main() {
double first, second, temp;
printf("Enter first number: ");
scanf("%lf", &first);
printf("Enter second number: ");
scanf("%lf", &second);
// value of first is assigned to temp
temp = first;
// value of second is assigned to first
first = second;
// value of temp (initial value of first) is assigned to second
second = temp;
// %.2lf displays number up to 2 decimal points
printf("\nAfter swapping, first number = %.2lf\n", first);
printf("After swapping, second number = %.2lf", second);
return 0;
}

Without using third variable


#include<stdio.h>
int main()
{
int a=10, b=20;
printf("Before swap a=%d b=%d",a,b);
a=a+b;//a=30 (10+20)
b=a-b;//b=10 (30-20)
a=a-b;//a=20 (30-10)
printf("\nAfter swap a=%d b=%d",a,b);
return 0;
}
Output:

Before swap a=10 b=20


After swap a=20 b=10

Ex No: 1b
Write a Program to display 3 students’ student name, roll number and marks of 4 subjects
and also display the total marks and percentage of each student.
Program:

#include <stdio.h>
int main() {
int i, j, total_marks;
float percentage;
char names[3][20];
int roll_numbers[3];
int marks[3][4];

// Input student details and marks


for(i = 0; i < 3; i++) {
printf("Enter name of student %d: ", i+1);
scanf("%s", &names[i]);
printf("Enter roll number of student %d: ", i+1);
scanf("%d", &roll_numbers[i]);
printf("Enter marks of student %d in 4 subjects: ", i+1);
for(j = 0; j < 4; j++) {
scanf("%d", &marks[i][j]);
}
printf("\n");
}

// Display student details and marks


for(i = 0; i < 3; i++) {
printf("Name: %s\n", names[i]);
printf("Roll Number: %d\n", roll_numbers[i]);
printf("Marks: ");
total_marks = 0;
for(j = 0; j < 4; j++) {
printf("%d ", marks[i][j]);
total_marks += marks[i][j];
}
percentage = ((float) total_marks / 400) * 100;
printf("\nTotal Marks: %d\n", total_marks);
printf("Percentage: %.2f\n\n", percentage);
}

return 0;
}

Output:
Enter the name of the student: Abi
Enter the roll number of student 1: 10
Enter the marks of student 1 in 4 subjects: 45 55 65 75
Enter the name of the student: Babu
Enter the roll number of student 1: 20
Enter the marks of student 1 in 4 subjects: 98 97 64 54
Enter the name of the student: Catherin
Enter the roll number of student 1: 30
Enter the marks of student 1 in 4 subjects: 67 65 68 63

Name: Abi
Roll Number: 10
Marks: 45 55 65 75
Total Marks: 240
Percentage: 60.00

Name: Babu
Roll Number: 20
Marks: 98 97 64 54
Total Marks: 313
Percentage: 78.25

Name: Catherin
Roll Number: 30
Marks: 67 65 68 63
Total Marks: 263
Percentage: 65.75

Ex No: 1c Write a C program to calculate area and circumference of a circle.


Program:

#include<stdio.h>
int main()
{
float radius, area,circumference;
printf("\nEnter the radius of Circle : ");
scanf("%d", &radius);
area = 3.14 * radius * radius;
circumference = 2*3.14*radius;
printf("\n Area of Circle : %f", area);
printf(“\n Circumference of the circle : %f”, circumference);
return (0);
}

Output:
Enter radius of a circle : 1
Area of circle : 3.14
Circumference : 6.28

Write a C program to find whether a character is consonant or vowel using switch statement.
Illustrate jumping statements in C
Ex No: 2a

Write a C program to input two numbers and display the maximum number using if-else.

Program
#include <stdio.h>

int main() {
int a, b;
printf("Enter Two Integers\n");
scanf("%d %d", &a, &b);

if (a > b)
{
/* a is greater than b */
printf("%d is Largest\n", a);
}
else if (b > a)
{
/* b is greater than a*/
printf("%d is Largest\n", b);
}
else
{
printf("Both Equal\n");
}

return 0;
}

Output:
Enter Two Integers
36
6 is Largest

Enter Two Integers


72
7 is Largest
Enter Two Integers
55
Both Equal

Ex No: 2b:
Write a C program to find whether a character is consonant or vowel using switch statement.

You might also like