Uppala Bharath Kumar

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 117

CSE18R151

PROGRAMMING IN C -LAB
RECORD

Name: Bharath kumar Uppala


REG.NO-9920004404
1

REPORT FOR THEORY WITH PRACTICAL COMPONENT


PROGRAMMING IN C – CSE18R153

Submitted by
UPPALA BHARATH KUMAR [9920004404]

Under the guidance of


Dr.B.S.Murugan, M.Tech., Ph.D.
(Associate Professor, Department of Computer Science and Engineering)
in partial fulfillment for the award of the degree
of
BACHELOR OF TECHNOLOGY
in
COMPUTER SCIENCE AND ENGINEERING
of

KALASALINGAM ACADEMY OF RESEARCH AND


EDUCATION (Deemed to be University)
Anand Nagar, Krishnankoil – 626 126

Academic Year Even Semester (2020-21)

KALASALINGAM ACADEMY OF RESEARCH AND EDUCATION


(Deemed to be University)
ANAND NAGAR, KRISHNANKOIL – 626 126
2

BONAFIDE CERTIFICATE

This is to certify that the Theory with Practical Component Report titled
“Programming in C ” is a bonafide record of the work done by Uppala
Bharath Kumar(9920004404) in partial fulfillment of the requirements for the
award of the degree of Bachelor of Technology in Specialization of the
Computer Science and Engineering, during the Academic year Even Semester
(2020-2021).

Dr.B.S.Murugan, M.Tech. Ph.D., Dr.A.Francis Saviour, M.E., Ph.D.,

Associate Professor & Supervisor Professor & Head


Department of CSE Department of CSE
3

ACKNOWLEDGEMENT
First and foremost, I wish to thank the Almighty God for his grace and
benediction to complete this Project work successfully. I would like to convey my
special thanks from the bottom of my heart to my dear Parents and affectionate
Family members for their honest support for the completion of this Project work.

I express deep sense of gratitude to “Kalvivallal” Thiru. T. Kalasalingam


B.com., Founder Chairman, “Ilayavallal” Dr.K.Sridharan Ph.D., Chancellor,
Dr.S.ShasiAnand, Ph.D., Vice President (Academic) , Mr.S.Arjun Kalasalingam
M.S., Vice President (Administration) , Dr.S.Saravanasankar Ph.D., Vice-
Chancellor, Dr.V.Vasudevan Ph.D., Registrar , Dr.P.Deepalakshmi M.E., Ph.D.,
Dean (School of Computing) . And also a special thanks to Dr.A.Francis Saviour
Durairaj M.E., Ph.D., Professor & Head , Department of CSE, Kalasalingam
Academy of Research and Education for granting the permission and providing
necessary facilities to carry out Project work.
I would like to express my special appreciation and profound thanks to my
enthusiastic Project Supervisor Dr.B.S.Murugan M.Tech., Ph.D., Associate
Professor/ CSE of Kalasalingam Academy of Research and Education [KARE] for his
inspiring guidance, constant encouragement with my work during all stages. I am
extremely glad that I had a chance to do my Project under my Guide, who truly
practices and appreciates deep thinking. I will be forever indebted to my Guide for all
the time he has spent with me in discussions. And during the most difficult times
when writing this report, he gave me the moral support and the freedom I needed to
move on.

Besides my Project guide, I would like to thank the rest of Class committee
members and all faculty members and Non-Teaching staff for their insightful
comments and encouragement. Finally, but by no means least, thanks go to all my
school and college teachers, well wishers, friends for almost unbelievable support.
4
5

S.NO PROGRAMME NAME DATE PAGE NO

1 SIMPLE INTERST 25/2/21 6

2 SUM OF TWO NUMBERS 25/2/21 8

3 AREA OF CIRCLE 25/2/21 10

4 CELIUS TO FARHENHEIT 25/2/21 12

5 FARHENHEIT TO CELIUS 25/2/21 14

6 SORTING OF THREE NUMBERS 25/2/21 16

7 SUM OF DIGITS 25/2/21 19

8 REVERSING A NUMBER 25/2/21 21

9 PALINDROME CHECKING 25/2/21 23

10 FACTORIAL NUMBER 25/2/21 25

11 ARMSTRONG NUMBER 25/2/21 27

12 SIMPLE CALUCULATOR 4/3/21 29

13 AVERAGE OF ARRAY 11/3/21 31

14 SORTING OF N NUMBERS 11/3/21 33

15 COUNT OF NO OF OCCURRENCE OF NUMBER 11/3/21 36

16 SEARCHING AN ELEMENT 11/3/21 38

17 TO FIND ODD OR EVEN 11/3/21 41

18 SWAPPING OF TWO NUMBERS 11/3/21 43

19 ADDITION OF TWO MATRIX 25/3/21 46

20 SUBTRACTION OF TWO MATRIX 25/3/21 50

21 MULTIPLICATION OF TWO MATRIX 25/3/21 55

22 STRING HANDLING FUNCTION 26/3/21 63

23 Function call by passing without arguments 1/4/21 67


without return statements.
24 Function call by passing with arguments without 1/4/21 70
return statements.
25 Function call by passing with arguments with 1/4/21 73
return statements.
26 factorial using recursion. 1/4/21 76

27 Fibonacci series using recursion. 15/4/21 79

28 Pointer to an array. 29/4/21 82


6

29 Pointers to an string. 29/4/21 92

30 Dynamic memory allocation. 29/4/21 95

31 Basic structures 13/5/21 98

32 Structure implementation to an array. 13/5/21 104

33 Structure passing to the function. 13/5/21 110


7

C-programming Lab

Programme-1: Simple interest.


Aim: To find the Simple interest using the basic C-program.
Algorithm:
Step 1: Start
Step 2: Read Principal Amount, Rate and Time
Step 3: Calculate Interest using formula SI= ((amount*rate*time)/100)
Step 4: Print Simple Interest
Step 5: Stop
Source code:
#include<stdio.h>
main()
{
int p ,n,r,s;
printf ("enter the values of the p n r");
scanf("%d%d%d",&p,&n,&r);
s=p*n*r/100;
printf(" the simple intrest is%d",s);
}
Output:
8

Result: Hence using above program we can find the simple interest.
9

Program-2: Sum of two numbers.


Aim: To find the sum of two numbers using the C-program.
Algorithm:
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop.
Source code:
#include<stdio.h>
main()
{
int a,b,c;
printf("Enter any two numbers");
scanf("%d%d",&a,&b);
c=a+b;
printf("%d is the sum",c);
}
Output:
10

Result: Hence by using above program sum of two numbers is


verified.
11

Program-3: Area of circle.


Aim: To find the area of the circle using the C-program.
Algorithm:
STEP 1: Take radius as input from the user using std input.
STEP 2: Calculate the area of circle using,
area = (3.14)*r*r.
STEP 3: Print the area to the screen.
Source code:
#include<stdio.h>
main()

{
int r;
float a;
printf("enter the value of r");
scanf("%d",&r);
a=3.14*r*r;
printf("the area of the circle is:%f",a);
}
Output:
12

Result: Hence the above program finding the area of circle is verified.
13

Program-4: conversion of celsius to Fahrenheit.


Aim: To find the value of conversion of celsius to Fahrenheit using C-
program.
Algorithm:
Step 1 : start
Step 2 : read temperature in centigrade
Step 3 : calculate Fahrenheit = 32 + (centigrade * (1.8));
Step 4 : display centigrade and Fahrenheit
Step 5 : stop.
Source code:
#include<stdio.h>
main()
{
int c;
float f;
printf("Enter the value of C");
scanf("%d",&c);
f=(1.8*c);
f=f+32;
printf("the farhen heat is:%f",f);
}
Output:
14

Result: Hence the above program conversion of Celsius to Fahrenheit


is verified.
15

Program-5: Conversion of Fahrenheit to Celsius.


Aim: To convert the value of Fahrenheit to the Celsius.

Algorithm:

Step-1: Read the temperature given in degree Fahrenheit.

Step-2: Convert the temperature in Fahrenheit into Celsius using the


formula : C=5/9*(F-32).

Step-3: Print the Fahrenheit and Celsius value of temperature.

Step-4: End.

Source code:

#include<stdio.h>

main()

int f;

float c;

printf("enter the value of F");

scanf("%d",&f);

c=(f-32)/1.8;

printf("the celcius value is:%f",c);

Output:
16

Result: Hence the above program conversion of farhenheit to Celsius is


verified.
17

Program-6: Sorting of three numbers.


Aim: To sort the Given three numbers in the increasing order.
Algorithm:
Step-1:Start.
Step -2: Accept three numbers from user (a, b, c).
Step-3: If a < b then goto step 4 else goto step 8.
Step-4: If a < c then goto step 5 else goto step 7.
Step-5: If b < c then goto step 9 else goto step 6.
Step-6: Interchange b and c and goto step 9.
Step-7: Interchange a and c and goto step 3.
Step-8: Interchange a and b and goto step 3.
Step-9: Display “Ascending order”.
Step-10: Display a, b, c.
Step-11: Stop.
Source code:
#include<stdio.h>
main()
{
int a,b,c;
printf("enter any three numbers");
scanf("%d%d%d",&a,&b,&c);
printf("After sorting");
if(a<b && a<c)
{
18

if(b<c)
printf("%d%d%d",a,b,c);
else
printf("%d%d%d",a,c,b);
}
if(b<a && b<c)
{
if (a<c)
printf("%d%d%d",b,c,a);
else
printf("%d%d%d",b,c,a);
}
if(c<a && c<b)
{
if(a<b)
printf("%d%d%d",c,a,b);
else
printf("%d%d%d",c,b,a);
}
}
Output:
19

Result: Hence By using above program sorting of three numbers is


verified.
20

Program-7: Sum of digits of a given number.


Aim: To find the sum of the given number using the C -program.
Algorithm:
Step 1: Get number by user

Step 2: Get the modulus/remainder of the number

Step 3: sum the remainder of the number

Step 4: Divide the number by 10

Step 5: Repeat the step 2 while number is greater than 0.

Source code:
#include<stdio.h>
main()
{
int n,s=0,r;
printf("enter the numbers");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
s=s+r;
n=n/10;
}
printf("sum of digits is:%d",s);
}
21

Output:

Result: Hence the sum of digits of a given number is verified.


22

Program-8: Reversing a given number.


Aim: To reverse a given number using the C-program.
Algorithm:
Step 1: Load the Necessary library files
Step 2: Start the main function
Step 3: Declare the variable ‘n’
Step 4: Initialize s=0
Step 5: Read the variable ‘n’
Step 6: While n > 0 do the following steps
Step 6.1: Extract the last digit i in the number
Step 6.2: Evaluate s= s*10+i
Step 6.3: Find n=n/10
Step 7: Print the reversed number as result
Step 8: Stop the main function
Step 9: End
Source code:
#include<stdio.h>
main()
{
int num,sum=0,rem;
printf("enter the number");
scanf("%d",&num);
while(num!=0)
{
23

rem=num%10;
sum=sum*10+rem;
num=num/10;
}
printf("the reversed number is:%d",sum);
}
Output:

Result: Hence the reversing the given number is verified using above
program.
24

Program-9: Palindrome number.


Aim: To check whether the given number is the palindrome or not.
Algorithm:
Step-1: Get the number from user

Step-2: Hold the number in temporary variable

Step-3: Reverse the number

Step-4: Compare the temporary number with reversed number

Step-5: If both numbers are same, print palindrome number

Step-6: Else print not palindrome number.

Source code:

#include<stdio.h>

main()

int num,rem,sum=0;

printf("enter the number");

scanf("%d",&num);

while(num!=0)

rem=num%10;

sum=sum*10+rem;
25

num=num/10;

if(sum=num)

printf("the number is palindrom");

else

printf("the number is not a palindrom");

Output:

Result: Hence the Palindrome number using above program is


verified.
26

Program-10: Factorial number.


Aim: To find the factorial of the given number.

Algorithm:
Step 1 → Take integer variable A
Step 2 → Assign value to the variable
Step 3 → From value A upto 1 multiply each digit and store
Step 4 → the final stored value is factorial of A.
Source code:
Code-1:
#include<stdio.h>
main()
{
int n,s=1,i;
printf("enter the number");
scanf("%d",&n);
while(n!=0)
{
s=s*n;
n=n-1;
}

printf("the factorial is:%d",s);


}
Code-2:
#include<stdio.h>
main()
{
int n,fact=1,i;
printf("enter the number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
27

fact=fact*i;
printf("the factorial is:%d",fact);
}
}
Output:

Result: Hence the finding the factorial of the given number is


verified.
28

Program-11: Armstrong number.


Aim: To check the given number is Armstrong or not using C
program.
Algorithm:
Step 1 → Take integer variable Arms
Step 2 → Assign value to the variable
Step 3 → Split all digits of Arms
Step 4 → Find cube-value of each digits
Step 5 → Add all cube-values together
Step 6 → Save the output to Sum variable
Step 7 → If Sum equals to Arms print Armstrong Number
Step 8 → If Sum not equals to Arms print Not Armstrong Number.

Source code:
#include<stdio.h>
main()
{
int d,n,sum=0,m;
printf("enter the number");
scanf("%d",&n);
n=m;
while(n>0)
{
d=n%10;
sum=sum+(d*d*d);
n=n/10;

}
if (n==sum)
printf("the number is armstrong");
else
printf("the number is not armstrong");
}
Output:
29

Result: Hence the above program Armstrong number is verified.


30

Program-12: Simple calculator.


Aim: User input for the end user to use simple calculator using
switch case in C-program.
Algorithm:
1 Step: BEGIN.

2 Step: PRINT ENTER YOUR CHOICE.

3 Step: ENTER YOUR CHOICE.

4 Step: ENTER TWO OPERANDS FOR OPERATION.

5 Step: USER WILL ENTER +,-,*,/ .

6 Step: SWITCH(OPERATOR)

7 Step: DO THE OPERATION.

8 Step: PRINT THE RESULT.

8 Step: EXIT.

Source code:
#include<stdio.h>
main()
{
int a,b,c,ch;
printf("enter the value");
scanf("%d%d",&a,&b);
printf("enter the choice 1.add 2.sub.3.mul 4.div");
scanf("%d",&ch);
switch(ch)
{
case 1:
c=a+b;
printf("%d",c);
break;
case 2:
c=a-b;
31

printf("%d",c);
break;
case 3:
c=a*b;
printf("%d",c);
break;
case 4:
c=a/b;
printf("%d",c);
break;
default:
printf("invalid");
}

}
Output:

Result: Hence the simple calculator by end user is verified.


32

Program-13: Average of n-numbers


Aim: To find the average of n-numbers using c-program.
Algorithm:
Step-1: The first printf statement will ask the user to enter n
value. For example, if the user enters 2, then the second printf
statement will ask the user to enter those two values, one
after the other.

Step-2: For loop will resist the user, not to enter more than
two values by using the condition i<n.

Step-3: In the next line, we added the entered value to sum.

Step-4: After completing this, it will start the second iteration.


For the 3rd iteration, the condition (i<n) will fail so, it will exit
from the For loop.

Step-5: Outside the loop, we calculated the average using the


formula sum/n. In our C Programming example, it is 30/2 =
15.

Source code:

#include<stdio.h>

main()

float avg,sum=0;

int a[100],i,n;

printf("how many numbers do you enter");

scanf("%d",&n);

printf("enter the numvers");

for(i=0;i<n;i++)
33

scanf("%d",&a[i]);

sum=sum+a[i];

avg=sum/n;

printf("sum=%f",sum);

printf("avg=%f",avg);

Output:

Result: Hence the program average of n numbers is verified.


34

Program-14: Sorting of n-numbers.


Aim: To sort the given number in the ascending order using C-
program.

Algorithm:

Step-1: First take the input from the user how many numbers
wish to enter.

Step-2: store the value.

Step-3: now give the input for numbers to enter.

Step-4: compare the each number with a another digit ao that


in a way n,n-1,n-2,,,,,using if and for loop.

Step-5: on comparing numbers if require save the number in


the temporary variable.

Step-6:print the output now.

Source code:

#include<stdio.h>

main()

int a[100],n,i,j,t;

printf("how many numbers do you enter");

scanf("%d",&n);

printf("enter the numbers");

for(i=0;i<n;i++)
35

scanf("%d",&a[i]);

for(i=0;i<n;i++)

for(j=0;j<n;j++)

if(a[i]<a[j])

t=a[i];

a[i]=a[j];

a[j]=t;

printf("the ascending order is");

for(i=0;i<n;i++)

printf("%d",a[i]);

Output:
36

Result: Hence the above program sorting of n-numbers is


verified.
37

Program-15: Count the number of occurrence.


Aim: To count the number of occurrenceof digit in the given
number’s.

Algorithm:

Step-1: Start

Step-2: Now take the input from the user how many numbers
he wants to enter.

Step-3: Now take the numbers from the user.

Step-4: Now take the input from user which element he wants
to search.

Step-5: Now using for loop check the each and every element
in the given input and add 1 to one variable using if condition
store the value.

Step-6: Now print the output.

Source code:

#include<stdio.h>

main()

int a[10],n,x,i,s=0;

printf("enter the value of n");

scanf("%d",&n);

printf("enter the numbers");

for(i=0;i<n;i++)
38

scanf("%d",&a[i]);

printf("enter the number to be searched");

scanf("%d",&x);

for(i=0;i<n;i++)

if(x==a[i])

s=s+1;

printf("the element present is %d"”times”,s);

Output:

Result: Hence the counting the occurance program is verified.


39

Program-16: Number is available or not.


Aim: To check whether the given number is available or not in
a set of elements.

Algorithm:

Step-1: Start

Step-2: Now take the input from the user how many numbers
he wants to enter.

Step-3: Now take the numbers from the user.

Step-4: Now take the input from user which element he wants
to search.

Step-5: Now using for loop check the each and every element
in the given input and add 1 to one variable using if condition
store the value.

Step-6: if that number is 0 then given number is not available if


that number is above 0 then the given number is available.

Step-7: Now print the output.

Source code:

#include<stdio.h>

main()

int a[10],n,x,i,s=0;

printf("enter the value of n");

scanf("%d",&n);

printf("enter the numbers");


40

for(i=0;i<n;i++)

scanf("%d",&a[i]);

printf("enter the number to be searched");

scanf("%d",&x);

for(i=0;i<n;i++)

if(x==a[i])

s=s+1;

if(s==0)

printf("the element present is not present");

else

printf(" the element is present");

Output:
41

Result: Hence the above program the given number is


available or not is verified.
42

Program-17: The given number is odd or even


Aim: To determine whether the given number is odd or even by
using c-program.

Algorithm:

Step 1 → Take integer variable A

Step 2 → Assign value to the variable

Step 3 → Perform A modulo 2 and check result if output is 0

Step 4 → If true print A is even

Step 5 → If false print A is odd

Source code:

#include<stdio.h>

main()

int a[100],i,n;

printf("how many numbers do you enter");

scanf("%d",&n);

printf("enter the numvers");

for(i=0;i<n;i++)

scanf("%d",&a[i]);

}
43

for(i=0;i<n;i++)

if(a[i]%2==0)

printf("the number is even");

else

printf("the number is odd");

//break;

Output:

Result: Hence the program the given number is odd or even is


verified.
44

Program-18: Swapping of two numbers.


Aim: To swap the two numbers by using the array using C-
program.

Algorithm:

Step-1:start.

Step-2: Take the input from the user how many numbers want
to enter (“here it is only for two numbers”).

Step-3: Now take the values from the user.

Step-4: Now take the temporary storage element to store num


2 value so that num 1 value can be stored in the num 2 so
temporary element value now store in num 1.

Step-5: Now print the values of num1 and num2.

Step-6: Stop.

Source code:

#include<stdio.h>

main()

int a[2],i,j,t,n;

printf("enter the how many elemts you do enter");

scanf("%d",&n);

printf("enter the elements");

for(i=0;i<n;i++)

{
45

scanf("%d",&a[i]);

for(i=0;i<n;i++)

for(j=i+1;j<n;j++)

t=a[i];

a[i]=a[j];

a[j]=t;

for(i=0;i<n;i++)

printf("%d",a[i]);

Output:
46

Result: Hence the above program swapping of two numnbers is


verified using array.
47

Program-19: Addition of two matrices.


Aim: To find the addition of two matrices using the C-program by 2D
array.

Algorithm:

START
Step 1 -> Input matrix 1 and matrix 2.
Step 2 -> If the number of rows and number of columns of matrix 1
and matrix 2 are equal then execute step 3 else addition not possible
Step 3 -> for i=1 to rows[matrix 1]
for j=1 to columns [matrix 1]
Input matrix 1 [i,j]
Input matrix 2 [i,j]
matrix 3 [i,j]= matrix 1 [i,j] + matrix 2 [i,j];
step 4-> Display matrix 3 [i,j];
STOP
Source code:
#include<stdio.h>
main()
{
int a[3][3],b[3][3],c[3][3],i,j;
printf("enter the values of matrix a");
for(i=0;i<3;i++)
48

for(j=0;j<3;j++)
{

scanf("%d",&a[i][j]);
}
}
printf("enter the values of matrix b");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
49

}
printf("the sum is");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
printf("%d",c[i][j]);
printf("\n");
}
Output:
50

Result: Hence the above program addition of two matrices is


verified.
51

Program-20 : Subtraction of two matrices.


Aim: To find the subraction of two matrices using the 2D array by C-
program.

Algorithm:

START
Step 1 -> Input matrix 1 and matrix 2.
Step 2 -> If the number of rows and number of columns of matrix 1
and matrix 2 are equal then execute step 3 else subtraction not
possible.
Step 3 -> for i=1 to rows[matrix 1]
for j=1 to columns [matrix 1]
Input matrix 1 [i,j]
Input matrix 2 [i,j]
matrix 3 [i,j]= matrix 1 [i,j] - matrix 2 [i,j];
step 4-> Display matrix 3 [i,j];
STOP
Source code:
#include<stdio.h>
main()
{
int a[3][3],b[3][3],c[3][3],i,j;
printf("enter the values of matrix a");
for(i=0;i<3;i++)
52

for(j=0;j<3;j++)
{

scanf("%d",&a[i][j]);
}
}
printf("enter the values of matrix b");
for(i=0;i<3;i++)
{

for(j=0;j<3;j++)
{

scanf("%d",&b[i][j]);
}
}
for(i=0;i<3;i++)
{

for(j=0;j<3;j++)
53

c[i][j]=a[i][j]-b[i][j];
}
}
printf("the diff is");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
printf("%d\n\n",c[i][j]);
printf("\n");
}
Output:
54
55

Result: Hence the above program subraction of two matrices is


verified.
56

Program-21: Multiplication of two matrices.


Aim: To find the multiplication of two matrices using 2-d array using
C-program.
Algorithm:
Step 1: Start the Program.

Step 2: Enter the row and column of the first (a) matrix.

Step 3: Enter the row and column of the second (b) matrix.

Step 4: Enter the elements of the first (a) matrix.

Step 5: Enter the elements of the second (b) matrix.

Step 6: Print the elements of the first (a) matrix in matrix form.

Step 7: Print the elements of the second (b) matrix in matrix form.

Step 8: Set a loop up to row.

Step 9: Set an inner loop up to the column.

Step 10: Set another inner loop up to the column.

Step 11: Multiply the first (a) and second (b) matrix and store the element

in the third matrix (c)


57

Step 12: Print the final matrix.

Step 13: Stop the Program.

Source code:

#include <stdio.h>

void main()

int a[25][25],b[25][25],c[25][25],i,j,k,r,s;

int m,n;

printf("Enter the first matrix\n");

scanf("%d%d",&m,&n);

printf("Enter the second matrix\n");

scanf("%d%d",&r,&s);

if(m!=r)
58

printf("\n The matrix cannot multiplied");

else

printf("\n Enter the elements of first matrix ");

for(i= 0;i<m;i++)

for(j=0;j<n;j++)

scanf("\t%d",&a[i][j]);

printf("\n Enetr the elements of second matrix ");

for(i=0;i<m;i++)

for(j=0;j<n;j++)
59

scanf("\t%d",&b[i][j]);

printf("\n The element of first matrix is");

for(i=0;i<m;i++)

printf("\n");

for(j=0;j<n;j++)

printf("\t%d",a[i][j]);

printf("\n The element of second matrix is");

for(i=0;i<m;i++)

printf("\n");
60

for(j=0;j<n;j++)

printf("\t%d",b[i][j]);

for(i=0;i<m;i++)

printf("\n");

for(j=0;j<n;j++)

c[i][j]=0;

for(k=0;k<m;k++)

c[i][j]=c[i][j]+a[i][k]*b[k][j];

}
61

printf("\n Multiplication of two matrix is");

for(i=0;i<m;i++)

printf("\n");

for(j=0;j<n;j++)

printf("\t%d",c[i][j]);

Output:
62
63

Result:Hence the above program Multiplication of two matrices is

verified.
64

Program-22: String handling functions.

Aim: To use the maxium string operations in the C-program

Algorithm:

step-1: start.

Step-2:Take the two strings from the user.

Step-3:Reverse the 1st string.

Step-4:calculate the string length.

Step-5:copy the string in another variable.

Step-6:Join the two strings.

Step-7:compare the both strings.

Step-8: now print the string compare.

Step-9:stop.

Source code:
65

#include<stdio.h>

#include<string.h>

main()

int d;

char x[100],y[100],z[100];

printf("enter the string");

scanf("%s",&x);

printf("enter another string ");

scanf("%s",y);

strcpy(z,x);

printf("\nreverse of 1st string is %s",strrev(x));

d=strlen(x);
66

printf("\nthr length of 1st string %d ",d);

printf("\nthe string after joining is %s ",strcat(strrev(x),y));

strcpy(x,y);

d=strcmp(z,y);

if(d==0)

printf("\nboth strings are equal");

else

printf("\nboth strings are not equal");

Output:
67

Result: Hence the using of maximum operators in string handling

functions are verified.


68

Program-23: Function call by passing without

arguments without return statements.

Aim: Swapping of two numbers using function call with out passing

arguments with out return statements.

Algorithm:

Step-1: start.

Step-2: Take the input from the user.

Step-3: now store the b value in temporary variable and store b value

in a and store the b value in a.

Step -4: now print the output.

Step-5: Stop.

Source code:

#include<stdio.h>
69

int swap();

int main()

swap();

swap()

int a,b,t;

printf("enter two numbers");

scanf("%d%d",&a,&b);

t=a;

a=b;

b=t;
70

printf("the swapped nos are%d%d",a,b);

Output:

Result: Hence the above program swapping of two numbers using

Function call by passing without arguments without return

statements is verified.
71

Program-24: function call by passing arguments

without return statement.

Aim: swapping of two numbers using function call by passing

arguments without return statement using C-program.

Algorithm:

Step-1: start.

Step-2: Take the input from the user.

Step-3: now store the b value in temporary variable and store b value

in a and store the b value in a.

Step -4: now print the output.

Step-5: Stop.

Source code:

#include<stdio.h>
72

int swap(int a,int b);

int main()

int a,b;

printf("enter the two numbers");

scanf("%d%d",&a,&b);

swap(a,b);

swap(int a,int b)

int t;

t=a;

a=b;
73

b=t;

printf("after swapping");

printf("%d%d",a,b);

Output:

Result: Hence the above program swapping of two numbers using

function call by passing arguments without return statement using C-

program is verified.
74

Program-25: Function call by passing arguments with

return statement.

Aim: To add the two numbers using the function call by passing

arguments with return statement using the C-program.

Algorithm:

Step-1: start.

Step-2: Take the two values from the user.

Step-3: Now call the function now add the two numbers in the user

defined function .

Step-4: now store the sum in another variable.

Step-5:Now print the output.

Step-6: stop.

Source code:
75

#include<stdio.h>

int add(int a,int b);

int main()

int a,b,c,d;

printf("enter any teo numbers");

scanf("%d%d",&a,&b);

c=add(a,b);

printf("the sum is%d",c);

return 0;

add(int a,int b)
76

int c;

c=a+b;

return (c);

Output:

Result: Hence the above program Adding of two numbers using

function call by passing arguments with return statement.


77

Program-26: factorial using recursion.

Aim: To find the factorial of the given number using recursion using

C-program.

Algorithm:

Step-1: start.

Step-2: Now declare the user defined function.

Step-3: Now take the input from the user.

Step-4: Now in the user defined function write the process for

factorial number.

Step-5: Now print the output.

Step-6: Stop.

Source code:

#include<stdio.h>
78

int fact(int n);

int main()

int n;

printf("enter the number");

scanf("%d",&n);

printf("the factorial is%d",fact(n));

int fact(int n)

if(n>0)

return(n*fact(n-1));
79

else

return 1;

Output:

Result: Hence the factorial using the recursion is verified.


80

Program-27: Fibonacci series(using recursion)

Aim: To find the Fibonacci series using the recursion in C-program.

Algorithm:

Step-1: start.

Step-2: Take the input from the user does how many series count

want by the user.

Step-3: Now add the successive addition using the user input using

the For loop.

Step-4 : Now print the output.

Step-5: Stop.

Source code:

#include<stdio.h>

int fib(int n);


81

int main()

int n,x,i;

printf("enter the nuner of values to be generated in the

series");

scanf("%d",&n);

for(i=1;i<=n;i++)

x=fib(i);

printf("\n%d",x);

}
82

int fib(int n)

if((n==1)||(n==0))

return 1;

else

return fib(n-1)+fib(n-2);

Output:
83

Result: Hence the above program is printing the Fibonacci series

using the recursion is verified.

Program-28: Pointer to an array.

Aim: Print of array elements using the pointer in C-program.

Algorithm:

Step-1: Start.

Step-2: Now initialise the variables and declare the pointer .

Step-3: Now find the address using pointer.

Step-4: Now print the array elements using the pointer.

Step-5: stop.

Source code:

#include<stdio.h>

const int max =3;


84

int main()

int var[]={10,100,200};

int i;

int *ptr=&var[1];

printf("*ptr-1 = %d\n",*(ptr-1));

printf("*ptr = %d \n",*ptr);

printf("*ptr+1 = %d \n",*(ptr+1));

return 0;

Output:
85

Code-2:

#include<stdio.h>

const int max =3;

int main()

int var[]={10,100,200};

int i;

int *ptr=&var[0];

for(i=0;i<max;i++)
86

printf("\n%d",*(ptr+i));

Output:

code-3:

#include<stdio.h>

const int max = 3;

int main ()

{
87

int var[] = {10, 100, 200};

int i, *ptr;

/* have address of the first element in pointer */

ptr = var;

i = 0;

while ( ptr <= &var[max - 1] )

printf("Address of var[%d] = %x\n", i, ptr );

printf("Value of var[%d] = %d\n", i, *ptr );

/* point to the previous location */

ptr++;

i++;

}
88

return 0;

Output:

Code-4:

#include<stdio.h>

const int max=3;

int main()

{
89

int var[]={10,100,200};

int i;

int *ptr[max];//assigning address

for(i=0;i<max;i++)

ptr[i]=&var[i];

for(i=0;i<max;i++)

printf("value of var[%d]=%d\n\n\n",i,*ptr[i]);

}
90

Output:

Code-5:

#include<stdio.h>

#include<conio.h>

const int max=3;

int main()

{
91

//clrscr();

//system('clear');

int var[]={10,100,200};

int i;

int *ptr[max];

for(i=0;i<max;i++)

ptr[i]=&var[i];

for(i=0;i<max;i++)

{
92

printf("value of var[%d]=%d\n\n\n",i,*ptr[i]);

Output:

Result: Hence the above program Pointers using the array is verified.
93

Program-29: Pointers to an string.

Aim: To print the string using the pointer in C-program.

Algorithm:

Step-1:start

Step-2: Now give the input for the user to enter the string.

Step-3: Now declare the pointer.

Step-4: now access the address using the pointer.

Step-5: Now print the output using the pointer.

Step-6:output.

Source code:

#include <stdio.h>
94

int main()

char str[100];

char *p;

printf("Enter any string: ");

fgets(str, 100, stdin);

// Assigning the base address str[0] to pointer//

p=str;

printf("The input string is: ");

while(*p!='\0')

printf("%c",*p++);

return 0;//no need of return statement here


95

Output:

Result: hence the above program pointers to an strings is verified.


96

Program-30: Dynamic memory allocation.

Aim:To use the string to allocate the memory in the Dynamic

memory allocation.

Algorithm:

Step-1: start.

Step-2: Now declare the Pointer and the variable.

Step-3:Now copy the string in an another variable.

Step-4:Now reallocate it.

Step-5: Now print the output.

Step-6: Stop.

Source code:

#include<stdio.h>

#include<string.h>
97

//#include<alloc.h>

#include<stdlib.h>

int main()

char *a;

a=(char*)malloc(6*sizeof(char));

strcpy(a,"HELLO");

printf("\nAFTER ALLOCATING A=%s\n",a);

a=(char*)realloc(a,13);

strcpy(a,"ARUPPUKOTTAI");

printf("\nAFTER REALLOCATING A=%s\n",a);

free(a);

a=NULL;
98

Output:

Result: Hence the dynamic memory allocation in C-program is

verified.
99

Program-31: Basic structures

Aim: To Implement the basic structures.

Algorithm:

Step-1:Start.

Step-2:Now declare the struct members.

Step-3:Now Now give the inputs for the struct members.

Step-4:stop.

Source code:

#include<stdio.h>

//#include<conio.h>

struct employee

{
100

int emp_id;

char name[20];

float salary;

char address[50];

int dept_no;

int age;

};

int main ()

struct employee e1, e2;

printf ("Enter the employee id of employee");


101

scanf("%d",&e1.emp_id);

printf ("Enter the name of employee");

scanf("%s",e1.name);

printf ("Enter the salary of employee");

scanf("%f",&e1.salary);

printf ("Enter the address of employee");

scanf("%s",&e1.address);

printf ("Enter the department of employee");

scanf("%d",&e1.dept_no);

printf ("Enter the age of employee");

scanf("%d" ,&e1.age);

printf ("Enter the employee id of employee");

scanf("%d",&e2.emp_id);
102

printf("Enter the name of employee");

scanf("%s",&e2.name);

printf("Enter the salary of employee");

scanf("%f",&e2.salary);

printf("Enter the address of employee");

scanf("%s",&e2.address);

printf("Enter the department of employee");

scanf("%d",&e2.dept_no);

printf("Enter the age of employee");

scanf("%d",&e2.age);

printf ("The employee id of employee is: %d", e1.emp_id);

printf ("The name of employee is: %s", e1.name);

printf ("The salary of employee is: %f", e1.salary);


103

printf ("The address of employee is: %s", e1.address);

printf ("The department of employee is: %d", e1.dept_no);

printf("the Age of the employee is:%d",e1.age);

printf ("The employee id of employee is : %d",e2.emp_id);

printf ("The name of employee is : %s",e2.name);

printf ("The salary of employee is: %f", e2.salary);

printf ("The address of employee is: %s",e2.address);

printf ("The department of employee is : %d",e2.dept_no);


104

printf ("The age of employee is : %d",e2.age);

Output:

Result: Hence the above program Structure declare is verified.


105

Problem-32: Array of structure.

Aim: To use the struct for the structure implementation to the array

in C-program.

Algorithm:

Step-1:start.

Step-2:Now declare the struct.

Step-3:now declare the struct members.

Step-4: Give the inputs for the struct members.

Step-5:now print the out put of the entered data.

Step-6:stop.

Source code:

#include <stdio.h>
106

//#include <conio.h>

struct employee

int emp_id;

char name[20];

float salary;
107

char address[50];

int dept_no;

int age;

};

int main()

struct employee e[5];

int i;
108

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

printf("Enter the employee id of employee");

scanf("%d",&e[i].emp_id);

printf ("Enter the name of employee");

scanf ("%s",e[i].name);

printf ("Enter the salary of employee");

scanf ("%f",&e[i].salary);

printf ("Enter the address of employee");

scanf ("%s", e[i].address);

printf ("Enter the department of employee");


109

scanf ("%d",&e[i].dept_no);

printf ("Enter the age of employee");

scanf ("%d",&e[i].age);

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

printf ("The employee id of employee is: %d",e[i].emp_id);

printf ("The name of employee is: %s",e[i].name);

printf ("The salary of employee is: %f",e[i].salary);

printf ("The address of employee is : %s",e[i].address);


110

printf ("The department of employee is : %d",e[i].dept_no);

//get ch();

Output:

Result: Hence the above program structure implementation to an

array is verified.
111

Program-33: Structure passing to the function.

Aim:To demonstrate the structure passing to the function in the C-

program.

Algorithm:

Step-1:start

Step-2:declare the struct

Step-3:declare the members of the struct.

Step-4:declare the function.

Step-5:give the user input for the struct members.

Step-6:call the function

Step-7:print the output

Step-8:stop

Source code:
112

#include <stdio.h>

struct employee

int emp_id;

char name[20];

float salary;

};

void printdata(struct employee e1);

int main ()
113

struct employee e1;

printf ("Enter the employee id of employee");

scanf("%d",&e1.emp_id);

printf ("Enter the name of employee");

scanf("%s",e1.name);

printf ("Enter the salary of employee");

scanf("%f",&e1.salary);

printdata(e1);

void printdata(struct employee emp)


114

printf ("\n The employee id of employee%d", emp.emp_id);

printf ("\nThe name of employee is : %s", emp.name);

printf ("\nThe salary of employee is : %f",emp.salary);

Output:

Result: Hence the above program structure to the function is verified.


115
116

You might also like