write lab manual c
TRANSCRIPT
Ex No.:9a FACTORIAL OF GIVEN NUMBER
Date :
AIM:
To write a program to find the factorial of the given number.
ALGORITHM:
Step-1: Start the Program
Step-2: Enter a number
Step-3: Set a loop to find factorial of the given number using the formula
fact=fact*i.
Step-4: Print the factorial of the given number
Step-5: Stop
RESULT:
Thus the program for factorial of given number is written and its output is
verified.
Ex No.:9b FIBONACI SERIES
Date :
AIM:
To write a program to generate the Fibonacci Series .
ALGORITHM:
Step-1: Start the Program
Step-2: Enter a number
Step-3: Check whether the number is zero or not. If zero print zero value. If not
zero go further.
Step-4: set a loop upto the given number.
Step-5: fib = fib + a; a = b; b=fib;
Step-6: Every increment in the loop prints the value of fib.
Step-7: After the execution of loop stops the program.
RESULT:
Thus the program for Fibonacci series is written and its output is verified.
Ex No.:9c Find Sum of Digits, Check the give number is palindrome or not.
Date :
AIM:
To find sum of digits, and to check the given number is palindrome or not.
ALGORITHM:
Step-1: Start the Program
Step-2: Enter a number
Step-3: Set a loop upto the number is not equal to zero.
Step-4: Rem num % 10
Step-5: Sum Sum + rem
Step-6: Rnum rnum * 20 + rem
Step-7: Num num/10
Step-8: After the end of the loop print the sum and reverse number of the digit.
Step-9: Find whether the reverse number is equal to the given number or not. If
equal the number is palindrome.
Step-10: If not equal the given number is not palindrome.
Step-11: Stop
RESULT:
Thus the program for sum of digits, and to check the given number is
palindrome or not is written and its output is verified.
Ex No.:9d LARGEST OF THREE NUMBERS
Date :
AIM:
To write a program to find the largest of three numbers.
ALGORITHM:
Step-1: Start the Program
Step-2: Read x,y,z
Step-3: big x
Step-4: Is y > big then big y
Step-5: Is z > big then big z
Step-6: Print Big
Step-7: Stop
RESULT:
Thus the program for largest of three numbers is written and its output is
verified.
Ex No.:9e MENU DRIVEN PROGRAM
Date :
AIM:
To write a menu driven program to find
1. Factorial of the given number
2. Prime number or not
3. Even number or odd number
4. Exit
ALGORITHM:
Step-1: Start the Program
Step-2: read num
Step-3: Enter your choice using switch statement
Step-4: If your choice 1.Find the factorial
Step-5: Set a loop upto to the entered number
Step-6: calculate factorial value
Step-7: Print the factorial value
Step-8: If your choice 2. Find whether the number is prime or not
Step-9: Set a loop upto number-1
Step-10: Check the number is divide by any number other than one and the
number itself.
Step-11: If divide absolutely then print the number is not a prime
Step-12: If not divide other than one and itself then print the number is prime
Step-13: If you choose the choice 3. Find whether the number is odd or even
Step-14: If the number is divide by 2 then print the number is even
Step-15: If the number is not dividing by 2 then print the number is odd
Step-16: if you choose the choice 4.Exit the program
Step-17: continue the program
RESULT:
Thus the program for menu driven is written and its output is verified.
Ex No.:9f TRAINGLE OF NUMBERS
Date :
AIM:
To write program to print Triangle of numbers.
ALGORITHM:
Step-1: Start the Program
Step-2: declare the variables i,j,k,l and n as “int” data type
Step-3: Read N numbers of line in a triangle.
Step-4: Initialize L=1
Step-5: for i=1,j=n-I to less than or equal to n
Step-5.1: for k=1 to less than or equal to j print “ “
Step-5.1.1 for k=1 to less than or
RESULT:
Thus the program for Triangle of numbers is written and its output is
verified.
Ex No.:10a INSERT AN ELEMENT IN AN ARRAY
Date :
AIM:
To write a program to insert an element in an array in the given position.
ALGORITHM:
Step 1: start the program.
Step 2: Enter the size of the array.
Step 3: Enter the element of the array.
Step 4: Print the element of the array.
Step 5: Enter the element to be inserted and its position in the array.
Step 6: Set a loop up to the position you enter.
Step 7: push the order of the position by one, which are greater, then the position
you entered.
Step 8: Insert the element in the position entered by you.
Step 9: Print the array after insertion of the element.
Step 10: stop.
RESULT:
Thus the program for insert an element in an array in the given position is
written and its output is verified.
Ex No.:10b ASCENDING AND DESCENDING ORDER
Date :
AIM:
To write a program to print the ascending and descending order of the given
array.
ALGORITHM:
Step 1: start the program.
Step 2: enter the size of the array.
Step 3: enter the elements of the array.
Step 4: set a loop up to the size minus one.
Step 5: set a inner loop up to the size of the array.
Step 6: check whether the next array element is greater than or not .
Step 7: if greater than exchange their position.
Step 8: if not greater than then go to the help.
Step 9: after the execution of inner loop the outer loop is executed.
Step 10: print the ascending order of the given array.
Step 11: print the descending order of the given array.
Step 12: stop.
RESULT:
Thus the program for ascending and descending order of the given array is
written and its output is verified.
Ex No.:10c LARGEST AND SMALLEST OF THE GIVEN
ARRAY
Date :
AIM:
To write a program to find the largest and smallest of the given array.
ALGORITHM:
Step 1: start the program.
Step 2: enter the size of the array.
Step 3: enter the elements of the array.
Step 4: print the array element.
Step 5: initialize the large and small is equal to the first element of the array.
Step 6: set a loop up to the array size.
Step 7: check the next element greater then the larger .if greater then assign next
element to the large.
Step 8: check the next element smaller then the larger .if smaller then the assign
next element to the small.
Step 9: print the value of large and small after the execution of the loop.
Step 10:stop.
.
RESULT:
Thus the program for find the largest and smallest of the given array is
written and its output is verified.
Ex No.:10d MULTIPLY TWO MATRIX
Date :
AIM:
To write a program to multiply two matrix.
ALGORITHM:
Step 1: start the program.
Step 2: enter the row and column of the A matrix.
Step 3: enter the row and column of the B matrix.
Step 4: enter the elements of the A matrix.
Step 5: enter the elements of the B matrix.
Step 6: print the element of the A matrix in the matrix form.
Step 7: print the element of the B matrix in the matrix form.
Step 8: set a loop up to row.
Step 9: set an inner loop up to column.
Step 10: set another loop up to column.
Step 11: multiply the A and B matrix and store the element in the C matrix.
Step 12: print the resultant matrix.
Step 13: stop.
RESULT:
Thus the program for multiply two matrix is written and its output is
verified.
Ex No.:10e STRING IS PALINDROME OR NOT
Date :
AIM:
To write a program to find whether the string is palindrome or not.
ALGORITHM:
Step 1: start the program.
Step 2: enter the string.
Step 3: find the string length using the strlen() function.
Step 4: print the string length.
Step 5: set a loop up to the half of the string length.
Step 6: compare every character above the middle character with the below
character.
Step 7: if any character equal prints the given string is palindrome.
Step 8: if the character is not equal then print the given string is not a palindrome.
Step 9: stop.
RESULT:
Thus the program for string is palindrome or not is written and its output is
verified.
Ex No.:10f TRANSPOSE THE GIVEN MATRIX.
Date :
AIM:
To write the program to transpose the given matrix.
ALGORITHM:
Step 1: start the program.
Step 2: enter the row and column of the matrix.
Step 3: enter the elements of the matrix.
Step 4: print the element of the matrix format.
Step 5: set the loop up to row.
Step 6: set the inner loop up to column.
Step 7: print the matrix element in the row wise.
Step 8: stop.
RESULT:
Thus the program for transpose the given matrix is written and its output is
verified.
Ex No.:11a STUDENT NAME, ROLL NO, AVERAGE MARKS AND
Date : THEIR GRADES USING STRUCTURES
AIM:
To write a program to print student name, roll no, average Marks and their
grades using structures.
ALGORITHM:
Step 1 Start the program
Step 2 Initialize the structure variable
Step 3 Enter the number of student
Step 4 Set a loop up to the number of student
Step 5 Enter the student name, roll no, average marks
Step 6 Find their grades
Step 7 Print the student name, roll no, average and their grade
Step 8 Stop
RESULT:
Thus the program to print student name, roll no, average Marks and their
grades using structures is written and its output is verified.
Ex No.:11b TO PRINT STUDENT NAME, ROLL NO, MARKS
Date : USING UNIONS
AIM:
To write a program to print the student name, roll no, marks using Unions.
ALGORITHM:
Step 1 Start the program
Step 2 Initialize the union variable
Step 3 Enter the number of student
Step 4 Set a loop up to the number of student
Step 5 Enter the student name, roll no, average marks
Step 6 Find their grades
Step 7 Print the student name, roll no, average and their grade
Step 8 Stop
RESULT:
Thus the program to print student name, roll no, average Marks and their
grades using unions is written and its output is verified.
Ex No.:11c ASSIGNING VALUES TO THE STRUCTURE
Date: VARIABLES AND RETRIEVING VALUES
AIM:
To write a program to assigning values to the structure variables and
retrieving values
ALGORITHM:
Step 1 Start the program
Step 2 Struct Std
Rno, Marks : integer
Name[10] : character
End Struct
Step 3 Read S.rno, S.name, S.marks
Step 4 Print S.rno, S.name, S.marks
Step 5 Stop
RESULT:
Thus the program to assigning values to the structure variables and
retrieving values is written and its output is verified.
Ex No.:11d MAINTAIN A STUDENT DATABASE USING
STRUCTURE
Date:
AIM:
To write a program to maintain a student database using structure.
ALGORITHM:
Step 1:Start
Step 2:Struct std
Rno marks; integer
Name[10] ; character
End struct
Step 3:Read total number of students n
Step 4:Read s[i].no , s[i].name , s[i].marks.
Step 5:Print s[i].no , s[i].name , s[i].marks.
Step 6: Stop.
RESULT:
Thus the program to maintain a student database using structure is
written and its output is verified.
Ex No.:11e NESTED STRUCTURES
Date:
AIM:
To write a program for Nested structures, the two structures are
declared within a single structure
ALGORITHM:
Step 1 Start
Step 2 Struct DOB
Dd,mm,yy : integer
End struct
Street Address
St[20], city[20] : character
End struct
Struct Student
Rno : integer
Name[20] character
Dt struct DOB
Add struct address
End struct
Step 3.: Read std.rno,std.name,std.dt.dd,std.dt.mm,std.dt.yy,
std.add.st,std.add.city
Step 4.:Print std.rno, std.name,std.dt.dd, std.dt.mm, std.dt.yy,std.add.st,
std.add.city
Step 5: Stop.
RESULT:
Thus the program for nested structures is written and its output is
verified.
Ex No.:11f PASSING STRUCTURE
Date:
AIM:
To write a program for passing structure members as a parameters to the
function.
ALGORITHM:
Step 1 Start
Struct Stud
Rno : integer
Name[20] : character
Marks : integer
End Stud
Step 2 Call function disp-rec (int, char[], int);
Step 3 Read st,rno, st.name, st.marks
Step 4 Call function disp-rec(st.rno, st.name, st.marks)
Step 5 Add more data if yes go to step4
Step 6 Stop
Disp-rec(int r, char n[], int m)
Step 6.1 Print r,n,m
Step 6.2 Return
RESULT:
Thus the program for passing structure is written and its output is
verified.
Ex No.:12a DISPLAY THE ADDRESS OF A VARIABLE
Date:
AIM:
To write a program to display the address of a variable
ALGORITHM:
Step 1: start
Step 2: declare a variable
Step3: assign data to the variable
Step 3: print the value of variable
Step 4: print the address of the variable
Step 5: stop
RESULT:
Thus the program to display the address of a variable is written and its
output is verified.
Ex No.:12b HOW THE VARIABLE CAN BE ACCESSED BY
POINTER
Date:
AIM:
To write a program to illustrates how the variable can be accessed by pointer
ALGORITHM:
Step 1: start a program
Step 2: declare normal variable a, and pointer variable *b
Step 3: read r
Step 4: a<-3.14*r *r
Step 5: d<-&a
Step6: print a
Step7: print &a
Step 8: print b
Step 9: print &b
Step 10: stop
RESULT:
Thus the program to illustrates how the variable can be accessed by
pointer is written and its output is verified.
Ex No.:12c USING THE POINTERS AND ARRAYS
Date:
AIM:
To write a program to using the pointers and arrays
ALGORITHM:
Step 1: start
Step2: declare array
Step3: read n
Step4: set a lap to get a value
Step5: read x[i]
Step6: set a lap to print the value
Set 7: print(x+i),*(x+i)
Step8: stop
RESULT:
Thus the program for using the pointers and arrays is written and its
output is verified.
Ex No.:12d ACCESSING THE STRING USING A POINTER
VARIABLE
Date:
AIM:
To write a program for accessing the string using a pointer variable
ALGORITHM:
Step 1: step
Step 2: declare character array
Step 3: read name
Step 4: print name using character array upto „\0‟
Step 5: stop
RESULT:
Thus the program for accessing the string using a pointer variable is written
and its output is verified.
Ex No.:12e DEMONSTRATE THE USE OF STRUCTURE POINTERS
Date:
AIM:
To write a program to demonstrate the use of structure pointers
ALGORITHM:
Step1: start
Struct book
Bno:integer
*bname[20]:character
Cost:integer
End book
Step2: read ptr->bno,ptr->bname,ptr->cost
Step3: while ptr<p+3 then
Print ptr->bno,ptr->bname,ptr->cost
Step4: stop
RESULT:
Thus the program to demonstrate the use of structure pointers is written and
its output is verified.
Ex No.:12f FIND FACTORIAL USING RECURISON
Date:
AIM:
To write a program to find the factorial of given number using recursion.
ALGORITHM:
Step-1: Start
Step-2: read num
Step-3: a recur(num)
Step-4: print num,a
Step-5: stop
Step-1: recur start
Step-2: fact 1
Step-3: is no=1
T:return 1
F:fact no*recur(no-1)
Step-4: return
RESULT:
Thus the program to find the factorial of given number using recursion is
written and its output is verified.
Ex No.:12g FILE PREMITIVES
Date:
AIM:
To write a program for introducing the file primitives, such as fopen, fclose,
fprintf.
ALGORITHM:
Step-1: Start
Step-2: Declare file pointer
Step-3: Declare variable
Step-4: open files std.dat
Step-5: read rno,name
Step-6: print rno,name
Step-7: stop
RESULT:
Thus the program for introducing the file primitives, such as fopen, fclose,
fprintf is written and its output is verified.