0% found this document useful (0 votes)
9 views65 pages

C Programming Practical Manual

Uploaded by

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

C Programming Practical Manual

Uploaded by

itadoriyuji4731
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

First Year

Laboratory Manual
EXPERIMENT LIST

Sr Name of experiment
no

1 Introduction to computer programming in C (PRACTICAL-SET—1)

2 Programs of control structure in C (PRACTICAL-SET—2)

3 Programs of creating patterns in C (PRACTICAL-SET—3)

4 Programs of arrays used in C (PRACTICAL-SET—4)

5 Programs of strings used in C (PRACTICAL-SET—5)

6 Programs of functions used in C (PRACTICAL-SET—6)

7 Programs of structures used in C (PRACTICAL-SET 7)

8 Programs of pointers used in C (PRACTICAL-SET—8)

9 Programs of dynamic memory management and file management in C (PRACTICAL-SET—9 &10)


PRACTICAL-SET—1
1. Write a program to print ―HELLO FRIENDS‖.
2. Write a program that reads two nos. from key board and gives their addition, subtraction,
multiplication, division, modulo, average.
3. Write a program to convert days into months and days.
4. Write a program to find whether the number is odd or even.
5. Write a program to solve Quadratic Equation.
6. Write a program to select & print the largest of the three nos. using Nested-If-Else
statement.

PRACTICAL-SET—2
1. Write a program to display multiplication table.
2. Write a program to print 1+1/2+1/3+1/4+………+1/N series.
3. Write a program to find sum of all integers greater than 100 & less than 200 and are
divisible by 5.
4. The distance between two cities (In KM) is input through key board. Write a program to
convert and print this distance in meters, feet, inches & centimeters.
5. Write a program to find sum of first N odd numbers. Ex. 1+3+5+7+………..+N.

PRACTICAL-SET—3
1. Write a program for use of putchar( ) and getchar( ) function.
2. Program to print Patterns.
a. *
**
***
****
b. 1 2 3 4 5
2345
345
45
5

c. AAAAA
BBBB
CCC
DD
E
d. 1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

PRACTICAL-SET—4
1. Write a program to print Fibonacci series. 1,1,2,3,5,……N
2. Write a program to reverse the digit.
3. Add, subtract and multiply two nos. using switch statement.
4. Write a program to add two matrixes.
5. Write a program to given no in ascending order.
6. W.A.P to read array of integers and print it in reverse order

PRACTICAL-SET—5
1. Write a program to count total words in text.
2. Find length of string using strlen( ) function.
3. Write a program to copy one string to another string.
4. Write a program to join two strings.
5. Write a program convert character into TOggLe character.
6. Find given string is palindrome or not using string library function.

PRACTICAL-SET—6
1. Write a function program to add first N numbers.
2. Write a function find out maximum out of three numbers.
3. Write a function power that computes x raised to the power y for integer x and y and
returns double type value.
4. Write a program to find factorial of a number using recursion.

PRACTICAL-SET—7
1. Define a structure type, personal, that would contain person name, date of joining and
salary. Using this structure, write a program to read this information for one person from
the key board and print the same on the screen.
2. Define a structure called cricket that will describe the following information:
a. Player name
b. Team name
c. Batting average

PRACTICAL-SET—8
1. Write a program using pointer and function to determine the length of string.
2. Write a program using pointer to compare two strings.
3. Write a program using pointer to concate two strings.
4. Write a program using pointer to copy one string to another string.

PRACTICAL-SET—9
1. Write a program that uses a table of integers whose size will be specified interactively at
run time.

PRACTICAL-SET—10
1. A program to illustrate reading files contents.
2. A program to illustrate the use of fgets( ).
PRACTICAL-SET—1
Problem statement:

1. Write a program to print ―HELLO FRIENDS

C Program:

#include <stdio.h>
void main()
{
clrscr();
printf("HELLO FRIENDS");
getch();
}

Output: HELLO FRIENDS


Problem statement:

2. Write a program that reads two nos. from key board and gives their addition, subtraction,
multiplication, division, modulo, average

C Program:

#include <stdio.h>
void main()
{
int first, second, add, subtract,
multiply; float divide,avg;
clrscr();
printf("Enter two integers\n");
scanf("%d%d", &first, &second);

add = first + second;


subtract = first - second;
multiply = first * second;
divide = first / (float)second;
avg= (first + second)/2;

printf("Sum = %d\n",add);
printf("Difference = %d\n",subtract);
printf("Multiplication = %d\n",multiply);
printf("Division = %.2f\n",divide);
printf("Avg = %.2f\n",avg);

getch();
}

8
Output:
Enter two integers
7 3
Sum = 10
Difference = 4
Multiplication = 21
Division= 2.33
Avg=5.00

9
Problem statement:

3. Write a program to convert days into months and days

C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

………………………………………………………………………………………………………

10
Problem statement:

4. Write a program to find whether the number is odd or even.


C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

………………………………………………………………………………………………………

11
Problem statement:

5. Write a program to solve Quadratic Equation.


C Program:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

12
Problem statement:

6. Write a program to select & print the largest of the three nos. using Nested-If-Else
statement.

C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

13
PRACTICAL-SET—2

14
Problem statement:

1. Write a program to display multiplication table.


C Program:

#include <stdio.h>
void main()
{
int n, i;
clrscr();
printf("Enter an integer to find multiplication table:");
scanf("%d",&n);
for(i=1;i<=10;++i)
{
printf("%d * %d = %d\n", n, i, n*i);
}
getch();
}
Output:
Enter an integer to find multiplication table:
9
9*1=9
9 * 2 = 18
9 * 3 = 27
9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9
* 8 = 72 9 * 9 = 81

9 * 10 = 90
15
Problem statement:

2. Write a program to print 1+1/2+1/3+1/4+………+1/N series


C Program:

#include <stdio.h>
void main()
{
double n, i;
clrscr();
printf("Enter value of n:");
scanf("%d",&n);
for (i=1; i<=n; i++)
{
if(i==1)
printf(“\n 1+”);
elseif(i==n)
printf(“ (1/%d) ”,i);
else
printf(“ (1/%d ) + ”, i);
}
getch();
}

Output
Enter value of n: 6

1 + (1/2) + (1/3) + (1/4) + (1/5) + (1/6)

16
Problem statement:

3. Write a program to find sum of all integers greater than 100 & less than 200 and are
divisible by 5.
C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

17
Problem statement:

4. The distance between two cities (In KM) is input through key board. Write a program to
convert and print this distance in meters, feet, inches & centimeters.

C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

18
Problem statement:

5. Write a program to find sum of first N odd numbers. Ex. 1+3+5+7+………..+N

C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

19
PRACTICAL-SET-3

20
Problem statement:

1. Write a program for use of putchar( ) and getchar( ) function.

C Program:

#include <stdio.h>
void main()
{
int c;
clrscr();
printf("Enter value of n: ");
c=getchar();
printf("\n you entered: ");
putchar(c);
getch();
}

When the above code is compiled and executed, it waits for you to input some text when you enter
a text and press enter then program proceeds and reads only a single character and displays it as
follows:

Enter value of n: this is test

you entered: t

21
Problem statement:
3. Program to print Patterns.
*
**
***
****
C Program:

#include <stdio.h>
void main()
{
int i,j,rows;
printf("Enter the number of rows: ");
scanf("%d",&rows);
for(i=1;i<=rows;++i)
{
for(j=1;j<=i;++j)
{
printf("%d ",j);
}
printf("\n");
}
getch();
}
Output:
Enter the number of rows: 5
*
**
***
****
*****

1
12
123
1234

22
Problem statement:

12345
2345
345
45
5

C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

23
Problem statement:

a. AAAAA
BBBB
CCC
DD
E
C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

24
Problem statement:

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

25
PRACTICAL-SET-4

26
Problem statement:
1. Write a program to print Fibonacci series. 1,1,2,3,5,……N
C Program:
#include<stdio.h>
void main()
{
int n, first = 0, second = 1, next,
c; clrscr();
printf("Enter the number of
terms\n"); scanf("%d",&n);

printf("First %d terms of Fibonacci series are :-


\n",n); for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second; second
= next;
}
printf("%d\n",next);
getch();
}

Output:
Enter the number of terms
6

27
First 6 terms of Fibonacci series are :-
0
1
1
2
3
5

28
Problem statement:
2. Write a program to reverse the digit.
C Program:
#include <stdio.h>
void main()
{
int n, reverse = 0;

printf("Enter a number to
reverse\n"); scanf("%d",&n);
while (n != 0)
{
reverse = reverse * 10;
reverse = reverse +
n%10; n = n/10;
}
printf("Reverse of entered number is = %d\n",
reverse); getch();
}

Output:
Enter a number to reverse 14563
Reverse of entered number is 36541

29
Problem statement:

3. Add, subtract and multiply two nos. using switch statement.

C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

30
Problem statement:

4. Write a program to add two matrixes.

C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

31
Problem statement:

5. . Write a program to given no in ascending order.

C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

32
Problem statement:

6. W.A.P to read array of integers and print it in reverse order

C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

33
PRACTICAL-SET-5

34
Problem statement:

1. Write a program to count total words in text.


C Program:

#include <stdio.h>
#include <string.h>

void main()
{
char s[200]; int
count = 0, i;

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


scanf("%[^\n]s", s);
for (i = 0;s[i] != '\0';i++)
{
if (s[i] == ' ')
count++;
}
printf("Number of words in given string are: %d\n", count +
1); getch();
}
Output:
Enter the string: I am Engineer
Number of words in given string are 3

35
Problem statement:

2. Find length of string using strlen( ) function.

Problem statement:

#include<string.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int strlength;
char *str;
clrscr();

printf("\nEnter the string:


"); gets(str);
strlength=strlen(str);
printf("\nThe length of the string is %d.",strlength);
getch();
}
Output:
Enter the string: Learn C Online
The length of the string is 14.

36
Problem statement:

3. Write a program to copy one string to another string.

C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

37
Problem statement:

4. Write a program to join two strings.

C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

38
Problem statement:

5. Write a program convert character into toggle character

C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

39
Problem statement:

6. Find given string is palindrome or not using string library function.

C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

0
PRACTICAL-SET-6

1
Problem statement:

1. Write a function program to add first N numbers.


C Program:
#include <stdio.h>
int sum(int n);
int main()
{
int num,add;
printf("Enter a positive integer:\n");
scanf("%d",&num); add=sum(num);
printf("sum=%d",add);

}
int sum(int n)
{
if(n==0)
return n;
else
return n+sum(n-1); /*self call to function sum() */
}
Output:
Enter a positive integer: 5
15

2
Problem statement:

2. Write a function find out maximum out of three numbers.


C Program:

#include <stdio.h>

/* function declaration */
int max(int num1, int num2, int num3);

int main ()
{
/* local variable definition
*/ int a,b,c;
printf(“Enter the value of three number a, b and c”);

int ret;

/* calling a function to get max value


*/ ret = max(a, b, c);

printf( "Max value is : %d\n", ret );

return 0;
}

/* function returning the max between two numbers


*/ int max(int num1, int num2, int num3)
{

3
/* local variable declaration */
int result;

if (num1 > num2)


{
if(num1>num3)
result = num1;
else
result = num3;
}
else
{
if(num2>num3)
result = num2;
else
result = num2;
}

return result;
}

4
Problem statement:

3. Write a function power that computes x raised to the power y for integer x and y and
returns double type value.
C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

5
Problem statement:

4. Write a program to find factorial of a number using recursion.


C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

6
PRACTICAL-SET-7

7
Problem statement:

1. Define a structure called cricket that will describe the following information:
d. Player name
e. Team name
f. Batting average
C Program:

#include<stdio.h>
#include<conio.h>

struct cricket
{
char pname[20];
char tname[20];
float bavg;
};

void main()
{
struct cricket s[5],t;
int i,j,n=5;
float p;
clrscr();

printf("\nEnter data of %d players",n);


for(i=0;i<n;i++)
{
printf("\nEnter PName TName BAvg for player-%d = ",i+1);
scanf("%s %s %f",s[i].pname,s[i].tname,&p);
s[i].bavg=p;
}

8
for(i=1;i<=n-1;i++)
{
for(j=1;j<=n-i;j++)
{
if(strcmp(s[j-1].tname,s[j].tname)>0)
{
t=s[j-1];
s[j-1]=s[j];
s[j]=t;
}
}
}

printf("\nAfter teamwise sorting... Player list is


"); for(i=0;i<n;i++)
{
printf("\n%-20s %-20s %.2f",s[i].pname,s[i].tname,s[i].bavg);
}

getch();
}

9
Problem statement:

2. Define a structure type, personal, that would contain person name, date of joining and
salary. Using this structure, write a program to read this information for one person from
the key board and print the same on the screen.
C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

0
PRACTICAL-SET-8

1
Problem statement:

1. Write a program using pointer and function to determine the length of string.
C Program:

#include<stdio.h>
#include<conio.h>

int string_ln(char*);

void main()
{
char str[20];
int length;
clrscr();
printf("\nEnter any string :
"); gets(str);

length = string_ln(str);
printf("The length of the given string %s is : %d", str,
length); getch();
}

int string_ln(char*p) /* p=&str[0] */


{
int count = 0;
while (*p != '\0') {
count++;
p++;
}
return count;
}

2
Output:
Enter the String : pritesh
Length of the given string pritesh is : 7

3
Problem statement:

2. Write a program using pointer to compare two strings.


C Program:

#include<stdio.h>
#include<conio.h>
main()
{
char *p,*q;
int i,j,flag=0;

printf("To compare two strings using pointers \n");


printf("\nInput two strings\n");
gets(p);
gets(q);
for(;*p!='\0' || *q!='\0';*p++,*q++)
{
if(*p|=*q)
flag=1;
}
if (flag==1)
printf("\nTwo Strings are
different"); else
printf("\nTwo Strings are same");
}

OUTPUT :
To compare two strings using pointers
Input two strings
clanguage
clanguage
Strings are same

4
Problem statement:
3. Write a program using pointer to concate two strings.
C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

5
Problem statement:

4. Write a program using pointer to copy one string to another string.


C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

6
PRACTICAL-SET-9

7
Problem statement:
1. Write a program that uses a table of integers whose size will be specified interactively at
run time.
C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

8
PRACTICAL-SET-10

9
Problem statement:
1. A program to illustrate reading files contents.
C Program:

#include <stdio.h>
#include <stdlib.h>

int main()
{
char ch, file_name[25];
FILE *fp;

printf("Enter the name of file you wish to see\n");


gets(file_name);

fp = fopen(file_name,"r"); // read mode

if( fp == NULL )
{
perror("Error while opening the file.\n");
exit(EXIT_FAILURE);
}

printf("The contents of %s file are :\n", file_name);

while( ( ch = fgetc(fp) ) != EOF


) printf("%c",ch);
fclose(fp);
return 0;
}
Output:
Enter the name of file you wish to see

0
[Link]
The contents of [Link] file are: Computer programming is logical.

1
Problem statement:
2. A program to illustrate the use of fgets( ).
C Program:

………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

………………………………………………………………………………………………………

2
3

You might also like