0% found this document useful (0 votes)
19 views68 pages

Lab Manual - 1739

Uvhuffhughh have excelled I am Ridham I don't have any Assessment Link recharge my branch ? ? ? ? ? ? ? ? to Find Largest number of Hjkn Huggcviu

Uploaded by

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

Lab Manual - 1739

Uvhuffhughh have excelled I am Ridham I don't have any Assessment Link recharge my branch ? ? ? ? ? ? ? ? to Find Largest number of Hjkn Huggcviu

Uploaded by

patelridham2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 68

Programming for problem solving

First Year

Laboratory Manual
VISION
To provide quality engineering education
and transforming students into
professionally competent and socially
responsible human beings.

MISSION
 To provide a platform for basic and
advanced engineering knowledge to
meet global challenges.
 To impart state-of-art know- how with
managerial and technical skills.
 To create a sustainable society through
ethical and accountable engineering
practices.
Programming for problem solving

L E COLLEGE, MORBI
IT DEPARTMENT

CERTIFICATE
This is to certify that Miss/Mr. __________________________
of 2ND semester Enrollment no. ____________________ has
satisfactorily completed her/his laboratory work in the
Programming for problem solving Subject as per G.T.U.
Guidelines.

Date Of submission: _______________

_____________ _____________
Head of Department Faculty

Programming for problem solving


EXPERIMENT LIST

Sr Name of experiment CO PO
no Mappin Mapping
g

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

2 Programs of control structure in C (PRACTICAL-SET—2) CO3 PO1, PO5

3 Programs of creating patterns in C (PRACTICAL-SET—3) CO3 PO1, PO5

4 Programs of arrays used in C (PRACTICAL-SET—4) CO3,CO5 PO1, PO3,


PO5, PO9,
PO10

5 Programs of strings used in C (PRACTICAL-SET—5) CO3 PO1, PO5

6 Programs of functions used in C (PRACTICAL-SET—6) CO4,CO5 PO1, PO3,


PO5, PO9,
PO10

7 Programs of structures used in C (PRACTICAL-SET 7) CO4,CO5 PO1, PO3,


PO5, PO9,
PO10

8 Programs of pointers used in C (PRACTICAL-SET—8) CO4,CO5 PO1, PO3,


PO5, PO9,
PO10

9 Programs of dynamic memory management and file management in C CO4,CO5 PO1, PO3,
(PRACTICAL-SET—9 &10) PO5, PO9,
PO10
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. *
**
***
****

IT Department, L E College, Morbi Page


3
Programming for problem solving

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.

IT Department, L E College, Morbi Page


4
Programming for problem solving

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( ).

IT Department, L E College, Morbi Page


5
Programming for problem solving

PRACTICAL-SET—1

IT Department, L E College, Morbi Page


6
PPS

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

IT Department, L E College, Morbi Page


7
PPS

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();
}

IT Department, L E College, Morbi Page


8
PPS

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

IT Department, L E College, Morbi Page


9
PPS

Problem statement:

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

C Program:

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

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

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

IT Department, L E College, Morbi Page 10


PPS

Problem statement:

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


C Program:

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

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

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

IT Department, L E College, Morbi Page 11


PPS

Problem statement:

5. Write a program to solve Quadratic Equation.


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

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

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

IT Department, L E College, Morbi Page 12


PPS

Problem statement:

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

C Program:

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

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

IT Department, L E College, Morbi Page 13


PPS

PRACTICAL-SET—2

IT Department, L E College, Morbi Page 14


PPS

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
IT Department, L E College, Morbi Page 15
PPS

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)

IT Department, L E College, Morbi Page 16


PPS

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:

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

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

IT Department, L E College, Morbi Page 17


PPS

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:

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

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

IT Department, L E College, Morbi Page 18


PPS

Problem statement:

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

C Program:

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

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

IT Department, L E College, Morbi Page 19


PPS

PRACTICAL-SET-3

IT Department, L E College, Morbi Page 20


PPS

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

IT Department, L E College, Morbi Page 21


PPS

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

IT Department, L E College, Morbi Page 22


PPS

Problem statement:

12345
2345
345
45
5

C Program:

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

IT Department, L E College, Morbi Page 23


PPS

Problem statement:

a. AAAAA
BBBB
CCC
DD
E
C Program:

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

IT Department, L E College, Morbi Page 24


PPS

Problem statement:

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

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

IT Department, L E College, Morbi Page 25


PPS

PRACTICAL-SET-4

IT Department, L E College, Morbi Page 26


PPS

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

IT Department, L E College, Morbi Page 27


PPS

First 6 terms of Fibonacci series are :-


0
1
1
2
3
5

IT Department, L E College, Morbi Page 28


PPS

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

IT Department, L E College, Morbi Page 29


PPS

Problem statement:

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

C Program:

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

IT Department, L E College, Morbi Page 30


PPS

Problem statement:

4. Write a program to add two matrixes.

C Program:

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

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

IT Department, L E College, Morbi Page 31


PPS

Problem statement:

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

C Program:

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

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

IT Department, L E College, Morbi Page 32


PPS

Problem statement:

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

C Program:

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

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

IT Department, L E College, Morbi Page 33


PPS

PRACTICAL-SET-5

IT Department, L E College, Morbi Page 34


PPS

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

IT Department, L E College, Morbi Page 35


PPS

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.

IT Department, L E College, Morbi Page 36


PPS

Problem statement:

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

C Program:

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

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

IT Department, L E College, Morbi Page 37


PPS

Problem statement:

4. Write a program to join two strings.

C Program:

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

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

IT Department, L E College, Morbi Page 38


PPS

Problem statement:

5. Write a program convert character into toggle character

C Program:

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

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

IT Department, L E College, Morbi Page 39


PPS

Problem statement:

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

C Program:

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

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

IT Department, L E College, Morbi Page 40


PPS

PRACTICAL-SET-6

IT Department, L E College, Morbi Page 41


PPS

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

IT Department, L E College, Morbi Page 42


PPS

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)
{

IT Department, L E College, Morbi Page 43


PPS

/* 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;
}

IT Department, L E College, Morbi Page 44


PPS

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:

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

IT Department, L E College, Morbi Page 45


PPS

Problem statement:

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


C Program:

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

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

IT Department, L E College, Morbi Page 46


PPS

PRACTICAL-SET-7

IT Department, L E College, Morbi Page 47


PPS

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;
}

IT Department, L E College, Morbi Page 48


PPS

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();
}

IT Department, L E College, Morbi Page 49


PPS

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:

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

IT Department, L E College, Morbi Page 50


PPS

PRACTICAL-SET-8

IT Department, L E College, Morbi Page 51


PPS

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;
}

IT Department, L E College, Morbi Page 52


PPS

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

IT Department, L E College, Morbi Page 53


PPS

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

IT Department, L E College, Morbi Page 54


PPS

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

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

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

IT Department, L E College, Morbi Page 55


PPS

Problem statement:

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


C Program:

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

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

IT Department, L E College, Morbi Page 56


PPS

PRACTICAL-SET-9

IT Department, L E College, Morbi Page 57


PPS

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

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

IT Department, L E College, Morbi Page 58


PPS

PRACTICAL-SET-10

IT Department, L E College, Morbi Page 59


PPS

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
IT Department, L E College, Morbi Page 60
PPS

Computer-programmming.txt
The contents of Computer-programmming.txt file are: Computer programming is logical.

IT Department, L E College, Morbi Page 61


PPS

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

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

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

IT Department, L E College, Morbi Page 62


PPS

IT Department, L E College, Morbi Page 63

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy