You are on page 1of 17

“ C “ LAB MANUAL

1.(a) CALCULATION OF SIN ( X)

Aim:

To find the sum of sine series

Sin (x) = x – (x 3 / 3!) +( x 5 / 5 ! ) - ……

Algorithm:

1. Read the values of x in degrees and convert it into radians and assign
1 to A.

2. Open a loop with index variable I ranging from 1 to 15.

3. Find the factorial of I and store it to J.

4. Calculate S+((X ** I ) * A ) / J and store it in S and change A to -A.

5. Increment the value I by two and continue the loop.

6. Print the value of S.

7. End.

b.CALCULATION OF COS ( X)

Aim:

To find the sum of cosine series

Cos (x) = 1 – (x 2 / 2!) +( x 4 / 4 ! ) ……

Algorithm:

1. Read the value of x in degrees and convert it into radians.

2. Assign -1 to A and 1 to S.

3. Open a loop with index variable I ranging from 2 to 15.

1
“ C “ LAB MANUAL

4. Find the factorial of I and store it to J.

5. Calculate S+((X ** I ) * A ) / J and store it in S and change A to -A.

6. Increment the value I by two and continue the loop.

7. Print the value of S.

8. End.

c.CALCULATION OF e x

Aim:

To find the sum of cosine series

e x = 1 + x + (x 2 / 2!) + ……….. ( x n / n ! )

Algorithm:

1. Read the value of x and assign 1 to s.

2. Open a loop with index variable i ranging from 1 to 15.

3. Find the factorial of i and store it in j.

4. Calculate s + ( x ** i ) / j and store it to s.

5. Increment the value of i by 1 and continue the loop.

6. Print the value of s.

7. End.

2
“ C “ LAB MANUAL

2.a. COUNTING THE NUMBER OF VOWELS, CONSONANTS, WORDS ,


WHITE SPACES IN A LINE OF TEXT
AND ARRAY OF LINES
Aim:

To count the number of vowels,consonants , words , white spaces in a line


of text and array of lines

Algorithm:

1. Read the line of text and an array of lines

2. The number of vowels are counted and printed.

3. The number of consonants are counted and printed.

4. The number words are counted and printed.

5. The number of white spaces are counted and printed.

6. End.

b. REVERSE A STRING AND CHECK FOR PALINDROME

Aim:

To reverse a string and check for palindrome

Algorithm:

1. Read a string

2. The entered string is reversed

3. The entered string and the reversed string are checked

4. If both the strings are equal then the entered string is a palindrome

5. Else the entered string is not a palindrome

3
“ C “ LAB MANUAL

6. End

c. SUBSTRING DETECTION AND COUNT

Aim:

To detect a substring and count the number of substrings in a line of text.

Algorithm:

1. Read a line of text

2. Enter the substrings to be detected

3. The entered substrings are detected and printed

4. The number of substrings in the line is found and printed

5. End

d. SUBSTRING REMOVAL

Aim:

To remove a substring from a line of text.

Algorithm:

1. Read a line of text

2. Enter the substring to be removed from the line

3. The substring if found in the line of text is printed

4. If not found , an error message is printed

5. End
e. FINDING AND REPLACING SUBSTRINGS

4
“ C “ LAB MANUAL

Aim:

To find a substring in a line of text and replace it with the given string

Algorithm:

1. Read a line of text

2. Enter the substring to be searched

3. Enter the substring to be replaced

4. Search the line of text for the given substring

5. If found , replace the substring with the given substring

6. End

a. GENERATING PERMUTATIONS ( nPr)

Aim:

To find the permutation using function

Algorithm:

1. Read the values of n and r

2. Find the values of n! using factorial function

3. Find the value of ( n – r ) ! using factorial function

4. Find the permutation using the following formula


nPr = n! / ( n – r ) !

5. Print the permutation value

6. End

5
“ C “ LAB MANUAL

Algorithm for Factorial function :

1. A function fact with k as its argument for finding the factorial

2. If k is equal to 1 then it is returned

3. If k is not equal to 1 then factorial is calculated using the formula


d = k * fact ( k – 1 )

4. The value of d is returned

b. GENERATING COMBINATIONS ( nCr)


Aim:

To find the binomial coefficient using function

Algorithm:

1. Read the value of n and r

2. Find the value of n ! using factorial function

3. Find the value of r ! using factorial function

4. Find the value of ( n – r ) ! using factorial function

5. Find the binomial coefficient using the following formula


nCr = n ! / ( r! * ( n – r ) ! )

6. Print the binomial coefficient value

7. End

c. FINDING GCD OF TWO NUMBERS

Aim:

To obtain the GCD of the two given numbers

6
“ C “ LAB MANUAL

Algorithm:

1. Read the values of a and b

2. Check whether a is greater than b and assign s=a else assign s=b

3. Initialize a1 as 1 and if a1 is less than or equal to s1 then increment


a

4. If a%a1 is equal to zero and b%a1 is equal to zero then assign gcd =
a1

5. Print the value of gcd

6. End.

d. FINDING MAXIMUM AND MINIMUM

Aim:

To find the maximum and minimum numbers in an array of numbers

Algorithm:

1. Read n numbers in an array

2. The largest number is found and printed

3. The smallest number is found and printed

4. End

e. FIBONACCI SEQUENCE

Aim:

To generate Fibonacci sequence 112358…..

7
“ C “ LAB MANUAL

Algorithm:

1. Declare and initialize two variables

2. Use loop and sum the two variables

3. The Fibonacci sequence is created and printed

4. End

f. TOWER OF HONOI

Aim:

To move a set of disks from source to destination using Tower of Honoi .

Algorithm:

1. Read the number of disks to be moved

2. Read the source , destination and Intermediate

3. Move the disks using Tower function.

4. Print each step in moving

5. End.

Algorithm for Tower function :

1. A function tower with n,a,b,c as its arguments for number of disks to


be moved , source , destination , intermediate respectively.

2. Move ( n – 1 ) disks from source to intermediate

3. Move nth disk from source to destination.

4. Move ( n – 1 ) disks from intermediate


a. ADDITION AND SUBTRACTION OF MATRICES

8
“ C “ LAB MANUAL

Aim:

To find the addition and subtraction of the given two matrices.

Algorithm:

1. Read the number of rows and columns of the matrices A and B.

2. Read the elements of the matrices A and B.

3. Calculate A( i,j ) + B ( i,j ) and assign it to C ( i,j ) with variables i and j .

4. Calculate A( i,j ) - B ( i,j ) and assign it to D ( i,j ) with variables i and j.

5. Print the values of the matrices C and D.

6. End

b. MATRIX MULTIPLICATION
Aim :

To obtain the multiplication value of the given two matrices.

Algorithm :

1. Read the order of matrices A and B.

2. Read the matrices A and B.

3. If the number of rows of matrix B is not equal to the number of


columns of matrix A then print that “ matrix multiplication is not
possible “.

4. For i equal to 1 to M ( number of rows )

5. For j equal to 1 to Q ( number of columns )

6. Initialize e[i][j] as zero.

9
“ C “ LAB MANUAL

7. For k value is 1 to N (number of columns in matrix A )

8. Calculate e[i][j ] = e[i][j] + a[i][j] * b[k][j]

9. Print the matrix e[i][j]

10.Repeat step 6

11.Repeat step 5

12.Stop.

c. TRANSPOSE OF A MATRIX

Aim:

To find the transpose of the given matrix.

Algorithm:

1. Read the number of rows and columns of the matrix A.

2. Read the elements of the matrix using variable A (i,j) inside a for loop
using variables i and j.

3. By using a nested loop with variables i , j ranging from 1 to row and j


to column , calculate or assign A(i,j) to B(i,j) and continue the loops.

4. Print the values of matrix B.

5. End.

d. DETERMINANT OF A MATRIX

Aim :

To find the determinant of a matrix.

Algorithm :

10
“ C “ LAB MANUAL

1. Declare the variable I,j,k,r,e as integers and d , r1 and array a as


Float.

2. Read the value for row and column.

3. Initialize p as 1. Repeat the loop until i is less than or equal to r

4. Initialize i as 1. Repeat the loop until j is less than or equal to r

5. Read the values for the array

6. Initialize j as i+1 and repeat the loop until j is less than or equal to
r– 1

7. Initialize j as i+1 and repeat the loop until j is less than or equal to r

8. Perform the calculation of a[i][j] by a[i][j] and store the result as r1

9. Initialize k as 1 and repeat the calculations until k is less than or equal


to r

10.Perform the calculation of a[i][k] – r1 * a[i][k] and store the result in


a[i][k]

11.Assign d as value 1.0

12.Initialize i as j and repeat until I is less than or equal to r

13.Calculate d as d * a[i][j]

14.Print the value of d

15.Stop

e. INVERSE OF A MATRIX

11
“ C “ LAB MANUAL

Aim:

To find the inverse of a given matrix.

Algorithm:

1. Read the number of rows and columns

2. If the rows and columns are not equal print that the rows and columns
are not equal

3. Initialize i as zero , i less than m

4. Initialize j as zero , j less than n

5. Read the elements of the matrix

6. Print the given matrix

7. Initialize i as zero , i less than m ; j equal to m ; j is less than 2*m

8. If i is equal to j – m , assign a[i][j] = 1 otherwise a[i][j] equal to zero

9. If i is not equal to j ; then do c = a[j][i] / a[i][i]

10.Initialize k as zero ; k less than 2*m and preincrement k

11.Do the calculation a[j][k] = a[j][k] – c*a[i][k]

12.Now a[i][j] = a[i][j] / a[i][i]

13.Print the inverse of the given matrix

14.End
LINEAR SEARCH
Aim:

To find a given number in an array using Linear Search method.

12
“ C “ LAB MANUAL

Algorithm:

1. Read the size of the array s and elements of the array using the
variable A(i)

2. Read the number to be searched in the array.

3. Find the existence of the number using an if statement inside a loop. If


not found write that the number is not found .

4. If the number is found write the number is found and print the
position of the number.

5. End.

BINARY SEARCH
Aim:

To find whether the given number is found in the given array or not by
using Binary Search method.

Algorithm:

1. Read the size of the array N and the elements of the array.

2. Sort the array in ascending order.

3. Read the number to be searched and assign 0 to L and N to U.

4. Calculate S = ( L+U+1 ) / 2 and check A (S) is equal to the number, if


so print as the number is found in the position S else check if A(S) is
greater than number , and if so assign S-1 to U else assign S+1 to L.
5. Check if L is lesser than or equal to U and if not so print the number
is not found else repeat steps 4 and 5

6. End.

13
“ C “ LAB MANUAL

INSERTION SORT

Aim:

To sort the given set of numbers in an array using insertion sorting

Algorithm:

1. Read n numbers in array

2. Initialize I with n-1 continue the loop till i<=0 and x<a[i] , decrement i
a[i+1] = a[i]
a[i]=x

3. Print the sorted numbers

4. End

SELECTION SORT

Aim:

To sort the given set of numbers in an array using selection sorting

Algorithm:

1. Read n numbers in array

2. The first element is compared with all the elements in the array one by
one

3. During the first iteration for example in the first step if the first element
is greater than the second element the both are swapped

4. The iteration is continued till n-1

5. The sorted numbers are printed

14
“ C “ LAB MANUAL

6. End

BUBBLE SORT

Aim:

To sort the given set of numbers in an array using bubble sorting

Algorithm:

1. Read n numbers in array

2. The first element is compared with the second element

3. The second element is compared with the third element

4. The iteration continues till n-1

5. The sorted numbers are printed

6. End

15
“ C “ LAB MANUAL

St. JOSEPH’S COLLEGE OF ENGINEERING


DEPARTMENT OF MCA

PROGRAMMING IN C

S.NO NAME OF THE EXPERIMENT


1. Summation of Series
a)Calculation Of SIN ( X)
b)Calculation Of COS ( X)
c) Calculation Of e x
5. String Manipulations
a) Counting The Number Of Vowels, Consonants ,
Words , White Spaces In A Line Of Text And Array
Of Lines
b) Reverse A String And Check For Palindrome

16
“ C “ LAB MANUAL

c) Substring Detection And Count


d) Substring Removal
e) Finding And Replacing Substrings
11. Recursion
a) nPr
b) nCr
c) GCD of two numbers
d) Finding Maximum and Minimum
e) Fibonacci Sequence
f) Tower Of Honoi
18. Matrix Manipulation
a) Addition And Subtraction Of Matrices
b) Matrix Multiplication
c) Determinant Of A Matrix
d) Inverse Of A Matrix
e) Transpose Of A Matrix
24. Searching and Sorting
a) Linear Search
b) Binary Search
c) Insertion Sort
d) Bubble Sort
e) Selection Sort

17

You might also like