C Lab Manual 2023
C Lab Manual 2023
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.
Write a C program to swap values of two variables with and without using third variable.
Program:
#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;
}
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];
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
#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
Ex No: 2b:
Write a C program to find whether a character is consonant or vowel using switch statement.