0% found this document useful (0 votes)
44 views

Lab Manual C AIDS - 2

The document provides a lab manual for a programming in C course. It includes details like lab rules, instructions, syllabus, marks scheme, list of experiments and resources. The objective is to teach programming concepts in C language through practical exercises in the computer lab.

Uploaded by

its me Lofy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Lab Manual C AIDS - 2

The document provides a lab manual for a programming in C course. It includes details like lab rules, instructions, syllabus, marks scheme, list of experiments and resources. The objective is to teach programming concepts in C language through practical exercises in the computer lab.

Uploaded by

its me Lofy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

LAB MANUAL
OF
Programming in C
(MCACCA1203)

MCA I Year I Semester


Academic Session
2023-2024

1
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

TABLE OF CONTENTS

S.No. Contents Page No.

1 Lab Rules 2-3

2 Instructions 4

3 Syllabus 5

4 Marks Scheme 6

5 Lab Plan 7

6 Lab objective 8

7 List of lab exercises 9

8 Resources 10

9 Experiments 11-47

2
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

LAB RULES
Responsibilities of Users
Users are expected to follow some obvious rules of conduct:

Always:

▪ Enter the lab on time and leave at the proper time.

▪ Wait for the previous class to leave before the next class enters.

▪ Keep the bag outside in the respective racks.

▪ Utilize lab hours in the corresponding.

▪ Turn off the machine before leaving the lab unless a member of lab staff has

specifically told you not to do so.

▪ Leave the labs at least as nice as you found them.

▪ If you notice a problem with a piece of equipment (e.g. a computer doesn't

respond) or the room in general (e.g. cooling, heating, lighting) please report it
to lab staff immediately. Do not attempt to fix the problem yourself.

Never:
3
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

▪ Don't abuse the equipment.

▪ Do not adjust the heat or air conditioners. If you feel the temperature is not

properly set, inform lab staff; we will attempt to maintain a balance that is
healthy for people and machines.

▪ Do not attempt to reboot a computer. Report problems to lab staff.

▪ Do not remove or modify any software or file without permission.

▪ Do not remove printers and machines from the network without being explicitly

told to do so by lab staff.

▪ Don't monopolize equipment. If you're going to be away from your machine for

more than 10 or 15 minutes, log out before leaving. This is both for the security
of your account, and to ensure that others are able to use the lab resources while
you are not.

▪ Don’t use internet, internet chat of any kind in your regular lab schedule.

▪ Do not download or upload of MP3, JPG or MPEG files.

▪ No games are allowed in the lab sessions.

▪ No hardware including USB drives can be connected or disconnected in the labs

without prior permission of the lab in-charge.

▪ No food or drink is allowed in the lab or near any of the equipment. Aside from

the fact that it leaves a mess and attracts pests, spilling anything on a keyboard
or other piece of computer equipment could cause permanent, irreparable, and

4
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

costly damage. (and in fact has) If you need to eat or drink, take a break and do
so in the canteen.

▪ Don’t bring any external material in the lab, except your lab record, copy and

books.

▪ Don’t bring the mobile phones in the lab. If necessary then keep them in silence

mode.

▪ Please be considerate of those around you, especially in terms of noise level.

While labs are a natural place for conversations of all types, kindly keep the
volume turned down.

If you are having problems or questions, please go to either the faculty, lab in-charge or
the lab supporting staff. They will help you. We need your full support and cooperation
for smooth functioning of the lab.

5
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

INSTRUCTIONS

Before entering in the lab

All the students are supposed to prepare the theory regarding the next experiment.
Students are supposed to bring the practical file and the lab copy.
Previous programs should be written in the practical file.
All the students must follow the instructions, failing which he/she may not be allowed in
the lab.

While working in the lab

Adhere to experimental schedule as instructed by the lab in-charge.


Get the previously executed program signed by the instructor.
Get the output of the current program checked by the instructor in the lab copy.
Each student should work on his/her assigned computer at each turn of the lab.
Take responsibility of valuable accessories.
Concentrate on the assigned practical and do not play games
If anyone caught red handed carrying any equipment of the lab, then he/she will have to
face serious consequences.

6
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Code: MCACCA1201 Programming in C 2 Credit [LTP:0-0-2]

Given the values of the variables x, y and z, write a program to rotate their values such that x
has the value of y, y has the value of z, and z has the value of x

Write a program that reads a floating point number and then displays the right-most digit of
the integral part of the number.

Write a C program to calculate the sum of digits of given number.

Program to find largest and smallest number from four given number.

Program to find whether a year is leap or not.

Write a C program in which enter any number by the user and perform the operation of Sum of
digits of entered number.

Write a C Program to convert Decimal number to Binary number.

Find the sum of this series up to n terms 1+2+3+4+5+6+………..

Program to print Armstrong’s numbers from 1 to 100.

Write a program to convert years into Minute, Hours, Days, Months, Seconds using switch ()
statements

Write a C menu driven program

7
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Write a program to generate the various pattern of numbers

Write a C Program to print the reverse of an integer number

Write a C program to perform the factorial of given number

Write a C program in which a function prime that returns 1 if its argument is a prime and
return zero otherwise.

Write a C program to calculate factorial of a number using recursion

Write a C program in which enter 10 elements by the user and perform the operation of
sorting in ascending order

Write a C program to perform to perform Matrix addition and multiplication operations

Write a program to determine the length of the string and find its equivalent ASCII codes.

Write a program to delete all the occurrences of the vowels in a given text. Assume that the
text length will be of one line

Write a program to maintain the library record for 100 books with book name, author’s
name, and edition, year of publishing and price of the book

MARKS SCHEME
8
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Examination Marks Scheme

A. Practical (Laboratory) Subjects:-

a. Continuous Internal Evaluation (CIE) 40%

- CIE-I (Pr.):Performance, Lab Record, Viva, Attendance and Discipline 20%

- CIE-II(Pr.):Performance, Lab Record, Viva, Attendance and Discipline 20%

b. Mid Semester Exam (MSE)– One 20 %

c. End Semester Exam (ESE) – One 40%

TOTAL 100 %

Internal Assessment System

Total Marks – 10

Performance
Attendance Discipline Record Total
& Viva

1 1 5 3 10

9
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

LAB PLAN

Total number of experiment 12


Total number of turns required 12
Number of turns required for

Experiment Number Turns Required Turn No.

Exp. 1 1 1

Exp. 2 1 2

Exp.3 1 3

Exp.4 2 4

Exp.5 1 5

Exp.6 1 6

Exp.7 1 7

Exp.8 2 8

Exp.9 1 9

Exp.10 1 10

Exp.11 1 11

Exp.11 1 11

Exp.12 1 12

Ex 13 1 13

Ex 14 1 14

Ex 15 1 15

Ex 16 1 16

Exp.17 1 17

10
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Ex. 18 1 18

Ex. 19 1 19

Ex. 20 1 20

Ex. 21 1 21

Distribution of lab hours


Attendance 05 minutes
Explanation of features of language 15 minutes
Explanation of experiment 15 minutes
Performance of experiment 70 minutes
Viva / Quiz / Queries 15 minutes

Total 120 minutes

Lab Objective

• To aware the student from the concept of virtualization.


• To introduce the vSphere platform to students
• Students will understand how to create virtual machine.

Virtualization is a technique, which allows sharing physical instance of a resource or an


application among multiple customers and organizations.
Therefore, to make students industry ready learning of Principal of virtualization is
necessary.

11
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

A. LIST OF EXPERIMENTS:

1 Given the values of the variables x, y and z, write a program to rotate their values such that x
has the value of y, y has the value of z, and z has the value of x

2 Write a program that reads a floating point number and then displays the right-most digit of
the integral part of the number.

3 Write a C program to calculate the sum of digits of given number.

4 Program to find largest and smallest number from four given number.

5 Program to find whether a year is leap or not.

6 Write a C program in which enter any number by the user and perform the operation of Sum of
digits of entered number.

7 Write a C Program to convert Decimal number to Binary number

Find the sum of this series up to n terms 1+2+3+4+5+6+………..

9 Program to print Armstrong’s numbers from 1 to 100.

10 Write a program to convert years into Minute, Hours, Days, Months, Seconds using switch ()
statements

11 Write a C menu driven program

12 Write a program to generate the various pattern of numbers

13 Write a C Program to print the reverse of an integer number

12
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

14 Write a C program to perform the factorial of given number

15 Write a C program in which a function prime that returns 1 if its argument is a prime and
return zero otherwise.

16 Write a C program to calculate factorial of a number using recursion

17 Write a C program in which enter 10 elements by the user and perform the operation of
sorting in ascending order

18 Write a C program to perform Matrix addition and multiplication operations

19 Write a program to determine the length of the string and find its equivalent ASCII codes.

20 Write a program to delete all the occurrences of the vowels in a given text. Assume that the
text length will be of one line

21

Write a program to maintain the library record for 100 books with book name, author’s
name, and edition, year of publishing and price of the book

13
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Resources for all the labs

Hardware :
1.Computer&
2.Peripheral devices

Software:
1. Turbo C ++
Text Books:
Let Us C by Yashvant Kanetkar
Reference Books:
Programming in ANSI C by E. Balagurusamy

Reference Websites:
1. https://www.programiz.com/c-programming
2. https://www.geeksforgeeks.org/c-programming-language/

14
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Experiments

15
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Experiment No.:1
Name of Experiment: Given the values of the variables x, y and z, write a program to
rotate their values such that x has the value of y, y has the value of z, and z has the value of x.

Aim: Swapping of two numbers


Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int x, y,z, temp;
clrscr();
printf("Enter first number \n");
scanf("%d", &x);
printf("Enter second number \n\n");
scanf("%d", &y);
printf("Enter third number \n\n");
scanf("%d", &z);
printf("Before swapping \n\t value of x: %d\n\t value of y: %d
\n\t value of z: %d\n\n ", x,y,z);
temp=x;
x=y;
y=z;
z=temp;
printf("After swapping \n\t value of x: %d\n\t value of y: %d \n\t
value of z: %d\n", x,y,z);
getch();

Output:

16
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Viva Questions:

Q.1 What is a Preprocessor in C?

Q.2 What is the use of stdio.h in this code?

Q.3 What is clrscr() in c?

Q. 4 What functions we use in C to take input and output? Name those two functions.

Experiment 2
Name of Experiment: Write a program that reads a floating point number and then displays
the right-most digit of the integral part of the number.

Aim: Display the rightmost digit of a floating point number

Code:
17
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

#include <stdio.h>

#include<conio.h>

int main() {

float fnum;

int rm, inum;

clrscr();

printf("Enter the number: \n");

scanf("%f", &fnum);

inum = (int)fnum;

rm= inum%10;

printf("The right most digit of the floating point number is:%d \n", rm);

getch();

return 0;

Output:

18
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Viva Questions:

Q.1 What is getch() in c?

Q.2 What is the format specifier of floating point number?

Q.3 What is type casting?

Q.4 What is conio.h?

Experiment 3

Name of Experiment: Write a C program to calculate the sum of digits of given number.

Aim: Calculate the sum of digits of given number

Code:
19
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

#include <stdio.h>
#include<conio.h>
int main()
{
int n, t, sum = 0, remainder;

clrscr();

printf("Enter an integer\n");
scanf("%d", &n);

t = n;

while (t != 0)
{
remainder = t % 10;
sum = sum + remainder;
t = t / 10;
}

printf("Sum of digits of %d = %d\n", n, sum);

getch()

return 0;
}

Viva Questions:

Q.1 What is loop?


Q2. State one difference between the while and do while loop.
20
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Q.3 Write the general format of the while loop.


Q.4 What is the difference between entry and exit control loop.

Experiment 4

Name of Experiment: Write a C program to find largest and smallest number from four
given number.
Aim: find the largest among four numbers

Code:

#include<stdio.h>

#include<conio.h>

int main(){

int num1, num2, num3, num4;

clrscr();

printf("Enter 4 numbers here...\n");

scanf("%d %d %d %d", &num1, &num2, &num3, &num4);

21
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

if(num1>num2&&num1>num3&&num1>num4){

printf("%d (num1) is greatest",num1);

else if(num2>num3&&num2>num4){

printf("%d (num2) is greatest",num2);

else if(num3>num4){

printf("%d (num3) is greatest",num3);

else{

22
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

printf("%d (num4) is greatest",num4);

getch();

return 0;

Output:

Viva Questions:

Q.1 What is a flowchart?

Q.2 What is variable?

Q.3 What is a compiler.


23
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Q.4 How many keywords (reserved words in C)?

Experiment 5

Name of Experiment: Write a C program to find whether the year is a leap year or not.
Aim: Find leap year

Code:

#include <stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);

// leap year if perfectly divisible by 400


if (year % 400 == 0) {
printf("%d is a leap year.", year);
}
// not a leap year if divisible by 100
// but not divisible by 400
else if (year % 100 == 0) {
printf("%d is not a leap year.", year);
}
// leap year if not divisible by 100
// but divisible by 4
else if (year % 4 == 0) {
printf("%d is a leap year.", year);
}
// all other years are not leap years
else {
printf("%d is not a leap year.", year);
}

return 0;
24
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Output:

Enter a year: 1900


1900 is not a leap year.

Viva Question:

Q.1 What is a leap year?

Q.2 Draw the flow chart for this program.

Q.3 Write the pseudo code for this program.

Q.4 Write the same logic of leap year with the help of operators.

Experiment 6

Name of Experiment: Write a C program in which enter any number by the user and
perform the operation of Sum of digits of entered number.
Aim: To take a number as input from the user and perform its sum.

Code:

#include <stdio.h>

int main()

25
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

int n, t, sum = 0, remainder;

printf("Enter an integer\n");

scanf("%d", &n);

t = n;

while (t != 0)

remainder = t % 10;

sum = sum + remainder;

t = t / 10;

printf("Sum of digits of %d = %d\n", n, sum);

return 0;

Output:

Viva Questions:

26
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Q.1 Draw the flowchart of the code.

Q.2 What is the use of nested if-else.

Q.3 What is an infinite loop?

Q.4 What statement you can use to terminate the infinite loop?

Experiment 7
Name of Experiment: Write a C Program to convert Decimal number to Binary number.
Aim: Convert decimal number into binary
Code:
#include <stdio.h>

void decToBinary(int n)
{
// array to store binary number
int binaryNum[32];

// counter for binary array


int temp=n;
int i = 0;
while (n > 0) {
// storing remainder in binary array
binaryNum[i] = n % 2;
n = n / 2;
i++;
}
printf("\n The binary equivalent of %d is:",temp);
// printing binary array in reverse order
for (int j = i - 1; j >= 0; j--)
printf("%d", binaryNum[j]);
}

// Driver program to test above function


int main()
{
27
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

int n;
printf("Enter any decimal number: ");
scanf("%d",&n);
//int n = 17;
decToBinary(n);
return 0;
}

Viva Questions:

Q.1 Convert these decimal numbers into binary

(a) 123
(b) 27

Q.2 What is the difference between a decimal and binary number system?

Q.3 What is the use of the continue statement in C?

Q.4 What is the use of break statement in C?

Experiment 8
Name of Experiment: Find the sum of this series up to n terms 1+2+3+4+5+6+……….
Aim: find the sum of n terms

Code:
​ #include<stdio.h>
28
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

​ int main() {
​ int n,i;
​ int sum=0;
​ printf("Enter the n i.e. max values of series: ");
​ scanf("%d",&n);
​ sum = (n * (n + 1)) / 2;
​ printf("Sum of the series: ");
​ for (i =1;i <= n;i++) {
​ if (i!=n)
​ printf("%d + ",i); else
​ printf("%d = %d ",i,sum);
​ }
​ return 0;
​ }

Output:

Viva Question:

Q.1 What is the difference between return and exit?

Q.2 What is the use of goto statement?

Q.3 What is the difference between continue and break statements?

Q.4 What is the use of the stdlib.h header file ?

Experiment 9
29
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Name of Experiment: Program to print Armstrong’s numbers from 1 to 100.


Aim: To Print Armstrong number from 1-100.
Code:

#include <stdio.h>

#include <math.h>

int main()

int num, originalNum, remainder, n, result;

printf("Armstrong numbers from 1 to 100 are:\n");

for (num = 1; num <= 100; num++)

originalNum = num;

n = 0;

result = 0;

while (originalNum != 0)

originalNum /= 10;

n++;

30
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

originalNum = num;

while (originalNum != 0)

remainder = originalNum % 10;

result += pow(remainder, n);

originalNum /= 10;

if (result == num) {

printf("%d ", num);

return 0;

Viva Questions:

31
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Viva Questions:
Q.1 What is an armstrong number?
Q.2 Write the count of armstrong numbers between 1-500.
Q.3 Why math library is used in the above program?

Experiment 10
Name of Experiment: Write a C menu driven program
Aim: menu driven program
Code:

32
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

#include <stdio.h>

int main() {

int choice = -1;

printf("MENU:\n1. Coffee\n2. Tea\n3. Exit");

while(1){

printf("\nEnter your choice:");

scanf("%d", &choice);

// If-else ladder

if(choice == 1){

printf("> Enjoy your Coffee!\n");

else if (choice == 2){

printf("> Enjoy your Tea!\n");

else if (choice == 3){

printf("BYE!!!\n");
33
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

break;

else{

printf("> Invalid Input\n");

return 0;

Viva Question:

Q.1 What is a menu driven program?


Q.2 Write the algorithm for this program.
Sol: Step 1: START

34
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

● Step 2: Take the choice input from the user.


● Step 3: Execute a specific set of statements according to the user's choice.
● Step 4: Repeat Step 3, till the user selects a valid option in Step 2.
● Step 5: STOP
Q.3 What is the use of exit() function in c?

Experiment 11
Name of Experiment: Write a program to generate the various pattern of numbers
Aim: To generate inverted half pyramid and full pyramid Pattern of numbers:

11.1 Inverted Half Pyramid


Code:
#include <stdio.h>

int main()
{
int n;
// User Input
printf("Enter the number of rows: ");
scanf("%d", &n);

//outer loop moving in the opposite direction


for (int i = n; i >= 1; --i)
{
for (int j = 1; j <= i; ++j)
{
printf("%d ", j);
}
printf("\n");
}
return 0;
}

35
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

11.2 Full Pyramid

Code:
#include <stdio.h>

int main()
{
int rows = 5;

for (int i = 0; i < rows; i++) {

for (int j = 0; j < 2 * (rows - i) - 1; j++) {


printf(" ");
}

for (int k = 0; k < 2 * i + 1; k++) {


printf("%d ", k + 1);
}
printf("\n");
}
return 0;
}

36
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Viva Questions:

Q.1 What part of knowledge do you need, to generate patterns in C?


Q.2 Why three for loops are implemented here in the above code?

Experiment 12
Name of Experiment: Write a program to convert years into Minute, Hours, Days, Months,
Seconds using switch () statements.
Aim: Program to convert year into Minute, Hours, Days, Months, Seconds using switch ()
statements.
Code:

Experiment 13
Name of Experiment: Write a C Program to print the reverse of an integer number.
Aim: To print the reverse of a number

Code: #include <stdio.h>

int main() {

int n, reverse = 0, remainder;

37
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

printf("Enter an integer: ");


scanf("%d", &n);

while (n != 0) {
remainder = n % 10;
reverse = reverse * 10 + remainder;
n /= 10;
}

printf("Reversed number = %d", reverse);

return 0;
}

Output:

Experiment 14
Name of Experiment: Write a C program to perform the factorial of given number
Aim: To find the factorial of a given number without using recursion.
Code:
#include<stdio.h>

int findFactorial(int);
int main(){
int i,factorial,num;

printf("Enter a number: ");


scanf("%d",&num);

38
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

factorial = findFactorial(num);
printf("Factorial of %d is: %d",num,factorial);

return 0;
}

int findFactorial(int num){


int i,f=1;

for(i=1;i<=num;i++)
f=f*i;

return f;
}

Output:

Experiment 15
Name of Experiment: Write a C program in which a function prime that returns 1 if its
argument is a prime and return zero otherwise.
Aim: To write a program in which a function prime that returns 1 if its argument is a prime
and returns zero otherwise.
Code:
#include<stdio.h>
int prime(int);
int main()
{
int n,p;
39
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

printf("Enter a number : ");


scanf("%d",&n);
p=prime(n);
if(p==1)
printf("%d is prime\n",n);
else
printf("%d is not prime\n",n);

return 0;
}
int prime(int n)
{
int i;
for(i=2;i<n;i++)
{
if(n%i==0)
return 0;
}
return 1;
}

Output:

Experiment 16
Name of Experiment: Write a C program to calculate factorial of a number using recursion
Aim: To find the factorial of a given number using recursion
Code:
#include<stdio.h>
40
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

long int fact(int n);


int main() {
int n;
printf("Enter a positive integer: ");
scanf("%d",&n);
printf("Factorial of %d = %ld", n, fact(n));
return 0;
}

long int fact(int n) {


if (n>=1)
return n*fact(n-1);
else
return 1;
}

Output:

Experiment 17
Name of Experiment: Write a C program in which enter 10 elements by the user and
perform the operation of sorting in ascending order.
Aim: C Program to enter 10 elements by user and perform sorting operation in ascending
order.
Code:
#include<stdio.h>
int main(){
int element[10],i,j,temp;
printf("enter 10 integer numbers:");
for(i=0;i<10;i++){
scanf("%d",&element[i]);
41
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

}
for(i=0;i<10;i++){
for(j=i+1;j<10;j++){
if(element[i]>element[j]){
temp=element[i]; //swapping element[i] with element[j]
element[i]=element[j];
element[j]=temp;
}
}
}
printf("Elements are now in ascending order:");
for(i=0;i<10;i++)
printf("%d\n",element[i]);
return 0;
}

Output

Experiment 18
42
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Name of Experiment: Write a C program to perform Matrix addition and multiplication


operations.
Aim: C program to perform Matrix addition and multiplication operations
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3], b[3][3], c[3][3]={0}, d[3][3]={0};
int i,j,k,m,n,p,q;
printf("Enter no. of rows and columns in matrix A: ");
scanf("%d%d",&m,&n);
printf("Enter no. of rows and columns in matrix B: ");
scanf("%d%d",&p,&q);
if(m!=p || n!=q)
{
printf("Matrix Addition is not possible");
return;
}
else if(n!=p)
{
printf("Matrix Multiplication is not possible");
return;
}
else
{
printf("Enter elements of matrix A: ");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d", &a[i][j]);
printf("Enter elements of matrix B: ");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d", &b[i][j]);
//Matrix Addition
for(i=0;i<m;i++)
for(j=0;j<n;j++)
c[i][j] = a[i][j] + b[i][j];
43
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

printf("\nResult of Matirx Addition:\n");


for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d ", c[i][j]);
printf("\n");
}
//Matrix Multiplication
for(i=0;i<m;i++)
for(j=0;j<q;j++)
for(k=0;k<p;k++)
d[i][j] += a[i][k]*b[k][j];
printf("\nResult of Matirx Multiplication:\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("%d ", d[i][j]);
printf("\n");
}
}
getch();
}

Output:

44
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

Experiment 19
Name of Experiment: Write a program to determine the length of the string and find its
equivalent ASCII codes.
Aim: C program to find length of string and find its equivalent ASCII code
Code:
#include<stdio.h>
int main() {
char string[10] = "Apoo";
int i=0, j;
45
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

// printf("Enter the String: ");


//fgets(string, 50, stdin);
for(j=0; string[j] !='\0'; j++);
printf("Length of string is: %d\n", j);

while(string[i]!='\0') {
printf("ASCII Value of %c=%d\n", string[i], string[i]);
i++;
}

return 0;
}

Output:

Experiment 20
Name of Experiment: Write a C program to delete all the occurrences of the vowels in a
given text. Assume that the text length will be of one line.
Aim: C program to delete all the occurrences of the vowels in a given text
Code:
#include<stdio.h>
#include<string.h>
void main(){
char str[20];
46
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

int len, i, j;

printf("Please Enter any String: ");


fgets(str, 20, stdin);
len=strlen(str);
for(i=0; i<len; i++){
if(str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u' || str[i]=='A' ||
str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U'){
for(j=i; j<len; j++){
str[j]=str[j+1];
}
len--;
}
}
printf("After Deleting the vowels, the String is: %s",str);

Output

Experiment 21
Name of Experiment: Write a C program to maintain the library record for 100 books with
book name, author’s name, and edition, year of publishing and price of the book.
Aim: C program to maintain the library record for 100 books
Code:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
47
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

#include<string.h>

struct library
{
char bk_name[30];
char author[30];
int edition;
float price;
};

int main()
{
struct library l[100];
char ar_nm[30],bk_nm[30];
int i,j, keepcount;
i=j=keepcount = 0;

while(j!=6)
{
printf("\n\n1. Add book information\n2. Display book information\n");
printf("3. List all books of given author\n");
printf("4. List the title of specified book\n");
printf("5. List the count of books in the library\n");
printf("6. Exit");

printf ("\n\nEnter one of the above : ");


scanf("%d",&j);

switch (j)
{
/* Add book */
case 1:

printf ("Enter book name = ");


scanf ("%s",l[i].bk_name);

printf ("Enter author name = ");


scanf ("%s",l[i].author);
48
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

printf ("Enter edition = ");


scanf ("%d",&l[i].edition);

printf ("Enter price = ");


scanf ("%f",&l[i].price);
keepcount++;

break;
case 2:
printf("you have entered the following information\n");
for(i=0; i<keepcount; i++)
{
printf ("book name = %s",l[i].bk_name);

printf ("\t author name = %s",l[i].author);

printf ("\t edition = %d",l[i].edition);

printf ("\t price = %f",l[i].price);


}
break;

case 3:
printf ("Enter author name : ");
scanf ("%s",ar_nm);
for (i=0; i<keepcount; i++)
{
if (strcmp(ar_nm, l[i].author) == 0)
printf ("%s %s %d %f",l[i].bk_name,l[i].author,l[i].edition,l[i].price);
}
break;

case 4:
printf ("Enter book name : ");
scanf ("%s",bk_nm);
for (i=0; i<keepcount; i++)
{
49
Lab Manual – MCACCA1103 –Programming in C la Poornima University, Academic Year 2023-24

if (strcmp(bk_nm, l[i].bk_name) == 0)
printf ("%s \t %s \t %d \t %f",l[i].bk_name,l[i].author,l[i].edition,l[i].price);
}
break;

case 5:
printf("\n No of books in library : %d", keepcount);
break;
case 6:
exit (0);

}
}
return 0;

Output:

50

You might also like