Department of Computer Science and Engineering
Laboratory Manual
of
Programming with C
is submitted to
Mrs. Halak Patel
Assistant Professor
Asha M. Tarsadia Institute of Computer Science and Technology
Uka Tarsadia University, Maliba Campus Bardoli, Gujarat
Semester — 1
(Winter 2024)
CERTIFICATE
This is to certify that Mr. /Ms. , Enrollment
No: of B. Tech. Computer Science and Engineering 1st semester
has satisfactorily completed his/her laboratory work of Programming with C during regular
term in academic year 2024-25.
Date of Submission:
Department Authority
Mrs. Halak Patel
Subject Teacher
Assistant Professor
Department of Computer Science and Engineering
Institute Stamp
Asha M. Tarsadia Institute of Computer Science and
Technology
Uka Tarsadia University
INDEX
Practical Title Date Sign
No.
1 Write a C program to show the usage of printf function.
2 Write a C program to print basic student details using library
function - printf().
************************************************
Student Name:
Branch:
Enrollment Number:
************************************************
3 Write a C program that takes user-entered number and
print the same number on a terminal screen.
4 Write a C program to take two integers from the user and
perform arithmetic operations (addition, subtraction,
division and multiplication) of two numbers.
5 Write a C program to take temperature from the user in F
and display the temperature in C.
6 Write a C program to display the area as an output of
various shapes (circle and rectangle) to the user. User will
enter necessary parameter values.
7 Write a C program that scan an integer from the user and
check whether the number is divisible by 3 or not.
8 Write a C program to take inputs of Month and Year from
the user and modify it in such a way that prints month
name given the month number by the user. (e.g. Input:
Month: 03, Year: 2023 Output: Month: March)
9 Write a C program to take three integers from the user
and print the largest among them.
10 Write a C program that display the grade of the student
given the marks.
11 Write a C program to basic calculator using switch
control structure.
12 Write a C program that prints the table of 1, 2 and 3 to
user using looping statements.
13 Write a C program that scan a number from the terminal
and print factorial of the number.
14 Write a C program that prints all the prime numbers
between 1 to 100.
15 Write a C program that prints various patterns using
looping statements.
16 Write a C program that accept the roll no and marks of
twenty students using an array. Display the same array to
user in appropriate tabular format.
17 Write a program to perform various string operations on
user entered string.
18 Write a C program to add two user-entered numbers using
user defined function named add(). Demonstrate the
variations of user defined function.
19 Write a C program to swap two user entered numbers using
user defined function named swap().
20 Write a C program to find factorial of user entered number
using recursion.
21 Write a simple C program to show the use of a pointer.
22 Write a C program using pointer to read an array of
integers and print the elements in reverse order.
23 Write a C program to store a character string in block of
memory space created by malloc() and then modify the same
to store a large string.
24 Define a structure type struct person that would contain
person_name, date_of_joining and salary. Using this structure,
write a C program to read this information for one person
from the user and print the same on the screen.
25 Write a C program that takes student details (student_name,
student_rool_no, student_address) for ten students from user.
Create a file named student_data.txt and store this record in
this file. Design a user defined function named fetch_record
that reads the file and displays the content on a terminal.
Programming with C Enrollment No.: 202403103510359
Practical 1
AIM : Write a C program to show the usage of printf function.
Code :
/************************************************
Student Name: Akash Saxena
Branch: B.Tech CE
Enrollment Number: 202403103510359
************************************************/
#include <stdio.h>
int main() {
int age = 69;
float height = 5.9;
char name[] = "Akash Saxena";
printf("Name: %s\n", name);
printf("Age: %d\n", age);
printf("Height: %.1f feet\n", height);
return 0;
}
Output :
AMTICS Page No.: 1
Programming with C Enrollment No.: 202403103510359
Practical 2
AIM : Write a C program to print basic student details using library function -
printf().
************************************************
Student Name:
Branch:
Enrollment Number:
************************************************
Code :
#include <stdio.h>
int main() {
char name[] = "Akash Saxena";
char branch[] = "B.Tech CE";
long enrollment_number = 202403103510359;
printf("************************************************\n");
printf("Student Name: %s\n", name);
printf("Branch: %s\n", branch);
printf("Enrollment Number: %ld\n", enrollment_number);
printf("************************************************\n");
return 0;
}
Output :
AMTICS Page No.: 2
Programming with C Enrollment No.: 202403103510359
Practical 3
AIM : Write a C program that takes user-entered number and print the same number
on a terminal screen
Code :
/************************************************
Student Name: Akash Saxena
Branch: B.Tech CE
Enrollment Number: 202403103510359
************************************************/
#include <stdio.h>
int main() {
int number;
printf("Enter a number: ");
scanf("%d", &number);
printf("You entered: %d\n", number);
return 0;
}
Output :
AMTICS Page No.: 3
Programming with C Enrollment No.: 202403103510359
Practical 4
AIM : Write a C program to take two integers from the user and perform arithmetic
operations (addition, subtraction, division and multiplication) of two
numbers.
Code :
/************************************************
Student Name: Akash Saxena
Branch: B.Tech CE
Enrollment Number: 202403103510359
************************************************/
#include <stdio.h>
int main() {
int num1, num2;
int sum, difference, product;
float quotient;
printf("Enter first integer: ");
scanf("%d", &num1);
printf("Enter second integer: ");
scanf("%d", &num2);
sum = num1 + num2;
difference = num1 - num2;
product = num1 * num2;
quotient = (float)num1 / num2;
printf("Addition: %d\n", sum);
printf("Subtraction: %d\n", difference);
printf("Multiplication: %d\n", product);
if (num2 != 0) {
printf("Division: %.2f\n", quotient);
} else {
AMTICS Page No.: 4
Programming with C Enrollment No.: 202403103510359
printf("Division: Cannot divide by zero!\n");
}
return 0;
}
Output :
AMTICS Page No.: 5
Programming with C Enrollment No.: 202403103510359
Practical 5
AIM : Write a C program to take temperature from the user in F and display the
temperature in C.
Code :
/************************************************
Student Name: Akash Saxena
Branch: B.Tech CE
Enrollment Number: 202403103510359
************************************************/
#include <stdio.h>
int main() {
float fahrenheit, celsius;
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("Temperature in Celsius: %.2f\n", celsius);
return 0;
}
Output :
AMTICS Page No.: 6
Programming with C Enrollment No.: 202403103510359
Practical 6
AIM : Write a C program to display the area as an output of various shapes (circle
and rectangle) to the user. User will enter necessary parameter values.
Code :
/************************************************
Student Name: Akash Saxena
Branch: B.Tech CE
Enrollment Number: 202403103510359
************************************************/
#include <stdio.h>
#define PI 3.14159
int main() {
int choice;
float area;
printf("Select a shape to calculate the area:\n");
printf("1. Circle\n");
printf("2. Rectangle\n");
printf("Enter your choice (1 or 2): ");
scanf("%d", &choice);
switch (choice) {
case 1: // Circle
{
float radius;
printf("Enter the radius of the circle: ");
scanf("%f", &radius);
area = PI * radius * radius;
printf("Area of the circle: %.2f\n", area);
break;
}
case 2: // Rectangle
{
AMTICS Page No.: 7
Programming with C Enrollment No.: 202403103510359
float length, width;
printf("Enter the length of the rectangle: ");
scanf("%f", &length);
printf("Enter the width of the rectangle: ");
scanf("%f", &width);
area = length * width;
printf("Area of the rectangle: %.2f\n", area);
break;
}
default:
printf("Invalid choice!\n");
}
return 0;
}
Output :
AMTICS Page No.: 8
Programming with C Enrollment No.: 202403103510359
Practical 7
AIM : Write a C program that scan an integer from the user and check whether the
number is divisible by 3 or not.
Code :
/************************************************
Student Name: Akash Saxena
Branch: B.Tech CE
Enrollment Number: 202403103510359
************************************************/
#include <stdio.h>
int main() {
int number;
printf("Enter an integer: ");
scanf("%d", &number);
if (number % 3 == 0) {
printf("%d is divisible by 3.\n", number);
} else {
printf("%d is not divisible by 3.\n", number);
}
return 0;
}
Output :
AMTICS Page No.: 9
Programming with C Enrollment No.: 202403103510359
Practical 8
AIM : Write a C program to take inputs of Month and Year from the user and modify
it in such a way that prints month name given the month number by the user.
(e.g. Input: Month: 03, Year: 2023 Output: Month: March)
Code :
/************************************************
Student Name: Akash Saxena
Branch: B.Tech CE
Enrollment Number: 202403103510359
************************************************/
#include <stdio.h>
int main() {
int month, year;
printf("Enter Month (1-12): ");
scanf("%d", &month);
printf("Enter Year: ");
scanf("%d", &year);
printf("Month: ");
switch (month) {
case 1:
printf("January\n");
break;
case 2:
printf("February\n");
break;
case 3:
printf("March\n");
break;
case 4:
printf("April\n");
break;
AMTICS Page No.: 10
Programming with C Enrollment No.: 202403103510359
case 5:
printf("May\n");
break;
case 6:
printf("June\n");
break;
case 7:
printf("July\n");
break;
case 8:
printf("August\n");
break;
case 9:
printf("September\n");
break;
case 10:
printf("October\n");
break;
case 11:
printf("November\n");
break;
case 12:
printf("December\n");
break;
default:
printf("Invalid Month!\n");
}
return 0;
}
Output :
AMTICS Page No.: 11
Programming with C Enrollment No.: 202403103510359
Practical 9
AIM : Write a C program to take three integers from the user and print the largest
among them.
Code :
/************************************************
Student Name: Akash Saxena
Branch: B.Tech CE
Enrollment Number: 202403103510359
************************************************/
#include <stdio.h>
int main() {
int num1, num2, num3;
// Prompt the user for three integers
printf("Enter first integer: ");
scanf("%d", &num1);
printf("Enter second integer: ");
scanf("%d", &num2);
printf("Enter third integer: ");
scanf("%d", &num3);
// Determine the largest number
int largest;
if (num1 >= num2 && num1 >= num3) {
largest = num1;
} else if (num2 >= num1 && num2 >= num3) {
largest = num2;
} else {
largest = num3;
}
// Print the largest number
AMTICS Page No.: 12
Programming with C Enrollment No.: 202403103510359
printf("The largest number is: %d\n", largest);
return 0;
}
Output :
AMTICS Page No.: 13
Programming with C Enrollment No.: 202403103510359
Practical 10
AIM : Write a C program that display the grade of the student given the marks.
Code :
/************************************************
Student Name: Akash Saxena
Branch: B.Tech CE
Enrollment Number: 202403103510359
************************************************/
#include <stdio.h>
int main() {
float marks;
// Prompt the user for marks
printf("Enter the marks obtained (0-100): ");
scanf("%f", &marks);
// Determine the grade based on marks
if (marks >= 90 && marks <= 100) {
printf("Grade: A\n");
} else if (marks >= 80) {
printf("Grade: B\n");
} else if (marks >= 70) {
printf("Grade: C\n");
} else if (marks >= 60) {
printf("Grade: D\n");
} else if (marks >= 0) {
printf("Grade: F\n");
} else {
printf("Invalid marks entered! Please enter marks between 0 and 100.\n");
}
return 0;
AMTICS Page No.: 14
Programming with C Enrollment No.: 202403103510359
Output :
AMTICS Page No.: 15