balamurugan2016.files.wordpress.com€¦ · web viewex. no: 1 odd or even. date : aim: to write a c...

45
Ex. No: 1 ODD OR EVEN Date : AIM: To write a C program find whether the given number is odd or even. ALGORITHM: Step 1 : Start. Step 2 : Read num, c. Step3 : if(num= = 0), then print it is neither odd or even otherwise go to step-4. Step4 : else calculate c=num%2. Step5 : if(c= =0), then print the given number is even, else print the given number is odd. Step6 : Stop.

Upload: ngothu

Post on 17-Apr-2019

213 views

Category:

Documents


0 download

TRANSCRIPT

Ex. No: 1 ODD OR EVEN

Date :

AIM:

To write a C program find whether the given number is odd or even.

ALGORITHM:

Step 1 : Start.

Step 2 : Read num, c.

Step3 : if(num= = 0), then print it is neither odd or even

otherwise go to step-4.

Step4 : else calculate c=num%2.

Step5 : if(c= =0), then print the given number is even,

else print the given number is odd.

Step6 : Stop.

Ex. No: 2 BIGGEST OF THREE NUMBERS

Date :

AIM:

To write a C program to find the biggest of three numbers.

ALGORITHM:

Step1 : Start.

Step2 : Read a, b, c,max.

Step3 : if(a>b), then if(a>c), then max = a,

otherwise max = c, else go to step-4.

Step 4 :- if(b>c), then max = b, else max = c.

Step5 : Print ‘max’ is the biggest value.

Step6 : Stop.

Ex. No: 3 ARMSTRONG OR NOT

Date :

AIM:

To write a C program to find whether the given number is Armstrong or not.

ALGORITHM:

Step 1 : Start.

Step 2 : Read n,t,s,r.

Step3 : Let t=n & s=0.

Step 4 : while(n>0), calculate r =n%10, s=s+(r*r*r) & n=n/10.

Step 5 : if(t = = s), print ‘t’ is an amstrong number , else print

‘t’ is not an amstrong number.

Step 6 : Stop.

Ex. No: 4 PERFECT OR NOT

Date :

AIM:

To write a C program to find whether the given number is perfect or not.

ALGORITHM:

Step 1 : Start.

Step 2 : Read num,temp=1,i=0,c=0,k.

Step 3 : while(temp<=num/2), k=num%temp.

Step 4 : if(k= = 0) ,c=temp+i & i=c, then temp++.

Step 5 : if(c= =num), print the given no. is a perfect no., else

print the given no. is not a perfect no.

Step 6: Stop.

Ex. No: 5 PALINDROME OR NOT

Date :

AIM:

To write a C program to find the given string is palindrome or not.

ALGORITHM:

Step 1 : Start.

Step 2 : Read input,copy,condition,length,i.

Step 3 : To find length of string use length=strlen(input).

Step 4 : for(i=0;i<length;i++) and to change the string to upper case use

input[i]=toupper(input[i]).

Step 5 : To copy the string use strcpy(input,copy).

Step 6 : Reverse the string by strrev(input).

Step7 : condition=strcmp(input,copy).

Step 8 : if(condition= = 0) print the given input is palindrome, else print the

given string is not palindrome.

Step 9 : Stop.

Ex. No: 6 SUM OF DIGITS

Date :

AIM:

To write a C program to print the sum of digits of a given number.

ALGORITHM:

Step 1 : Start.

Step 2 : Read num,sum=0,rem.

Step 3 : while(num>0), rem = num%10,sum =sum+rem,num=num/10

Step 4 : Print sum.

Step 5: Stop.

Ex. No: 7 FIBONACCI SERIES

Date :

AIM:

To write a C program to print the Fibonacci Series.

ALGORITHM:-

Step 1 : Start.

Step 2 : Read l=-1,j=1,n,k,i.

Step 3 : for(i=0,i<n,i++)

Step 4: k=l+j

Step 5 : Print sum.

Step 6 : l=j;

Step 7 : j=k;

Step 8 : Go to STEP 3.

Step 9: Stop.

Ex. No: 8 PRIME NUMBER OR NOT

Date :

AIM:

To write a C program that prints the given number is prime or not.

ALGORITHM:

Step 1 : Start.

Step2 : Read num,temp=2,k.

Step3 : While(temp<=num/2), k= num%temp

Step 4 : if k = 0

Step5: Print Number is Composite

Step6: temp++ goto step 3

Step 7: Print Number is Prime

Step8 : Stop.

Ex. No: 9 SUM OF ARRAY ELEMENTS

Date :

AIM:

To write a C program to print the sum of array of a given number.

ALGORITHM:

Step 1: Start.

Step 2: Read a[5],b[5],c[5],i,j,k.

Step 3: Get values for Array a[5].

Step 4: Get values for Array b[5].

Step 5: Array c[5] is Sum of Array a[5] and b[5].

Step 6: Print Array c[5].

Step 7: Stop.

Ex. No: 10 CALL BY VALUE

Date :

AIM:

To write a C program that calls a function by call by value.

ALGORITHM:

Step-1 : Start.

Step-2 : Read a,b.

Step-3 : Print a,b.

Step-4 : call swap(a,b)

Step-5 : Print a,b

Step-6 : Stop

Swap(a, b)

Step-1 : Start swap(a,b).

Step -2 : temp = a, a = b, b =temp.

Step-3 : Print a,b.

Step-4 : Return.

Ex. No: 11 CALL BY REFERENCE

Date :

AIM:

To write a C program that calls a function by call by reference.

ALGORITHM:

Step-1 : Start.

Step-2 : Read a,b.

Step-3 : Print a,b.

Step-4 : call function (&a,&b)

Step-5 : Print a,b

Step-6 : Stop

function(&a, &b)

Step-1 : Start function(*a,*b).

Step-2 : temp =* a, *a =*b,*b =temp.

Step -3 : Print a,b.

Step-4 : Return.

Ex. No:12 FACTORIAL

Date :

AIM:

To write a C program to print the Factorial of a given number.

ALGORITHM:

Step-1 : Start.

Step -2 : Read num,output.

Step-3 : output =fact(num).

Step -4: Definition of fact(num)

Step-5 : Read fact =1

Step -6 : While(num>0),fact =fact*num,num--.

Step-7 : Return fact.

Step-8 : Print fact

Step-9: Stop.

Ex. No:13 MATRIX ADDITION

Date :

AIM:

To write a C program to add two matrices.

ALGORITHM:

Step-1 : Start.

Step -2 : Declare a two dimensional array

Step-3 : Read two matrices

Step -4 : Use nested for loop

Step-5: Add two matrices

Step-6 : store the answer in array variable

Step -7 : Print result.

Step-8: Stop.

Ex. No:14 MATRIX MULTIPLICATION

Date :

AIM:

To write a C program to multiply two matrices.

ALGORITHM:

Step-1 : Start.

Step -2 : Declare a two dimensional array

Step-3 : Read two matrices

Step -4: Use nested for loop

Step-5: Multiply two matrices

Step -6 : store the answer in array variable

Step-7 : Print result.

Step -8: Stop.

Ex. No:15 PALINDROME

Date :

AIM:

To write a C program for palindrome checking.

ALGORITHM:

Step -1 : Start.

Step-2 : Declare a two array variables.

Step -3 : Read a string

Step-4 : Use string handling functions

Step -5: Compare the given two strings are same.

Step-6 : Display the message palindrome or not.

Step-7: Stop.

Ex. No:16 FUNCTION POINTER

Date :

AIM:

To write a C program for Function pointer.

ALGORITHM:

Step-1 : Start.

Step-2 : Declare a pointer variable as function.

Step -3 : Assigning address of function to pointer variable

Step-4 : Define a function definition as show()

Step -5: Call a function.

Step-6 : Display the message.

Step -7: Stop.

Ex. No:17 FUNCTION WITH VARIABLE NUMBER OF ARGUMENTS

Date :

AIM:

To write a C program for Function with variable number of arguments

ALGORITHM:

Step-1 : Start.

Step -2 : Include a header file called stdarg.h

Step-3 : Define a function as fun() with variable number of arguments.

Step -4 : Call the functions related to stdarg header file.

Step-5: Passing variable number of arguments as function arguments.

Step -6: Display the result.

Step-7: Stop.

Ex. No: 18 NESTED STRUCTURES

Date :

AIM:

To write a C program to use structures to print name and addressof student.

ALGORITHM:

Step-1 : Start.

Step -2 : Read Structure address,student.

Step-3 : Read structure members name,doorno,strtname,place,city.

Step -4 : Print structure members name,doorno,strtname,place,city.

Step-5 : Stop.

Ex. No:19 FILE HANDLING-SEQUENTIAL ACCESS

Date :

AIM:

To write a C program for file handling.

ALGORITHM:

Step-1 : Start.

Step -2 : Open a file in write mode and read mode.

Step-3 : Read a string and end with # symbol.

Step -4 : use putc() function to write the given message in file.

Step-5: use getc() function for read the given message as one by one character from

file.

Step-6: Display the message in the window read from file.

Step -7: Stop.

Ex. No:20 FILE HANDLING-RANDOM ACCESS (ftell() and rewind())

Date :

AIM:

To write a C program random access in file handling.

ALGORITHM:

Step-1: Start.

Step -2 : Declare two character array.

Step-3 : create a file in write mode.

Step -4 : check EOF is reached or not.

Step-5: use the function for handling the file.

Step -6: Display the output.

Step-7: Stop.

Ex. No:21 FILE HANDLING-ERROR HANDLING

Date :

AIM:

To write a C program for error handling in files.

ALGORITHM:

Step-1 : Start.

Step -2 : Open a file in open mode..

Step-3 : Read a string

Step -4 : Use Error handling functions for handle the errors.

Step-5: Close the file stream.

Step-6: Stop.

Ex. No: 22 ARRAY IMPLEMENTATION OF LIST ADT

Date:

AIM:

To implement the List ADT using arrays.

ALGORITHM:

Step 1: Start.

Step 2: Declare the necessary functions for implementation.

Step 3: Get the input from the user and store it an array.

Step 4: In Insertion, half of the elements to be shifted upwards and in deletion half of the

elements to be shifted downwards.

Step 5: Display the output using an array.

Step 6: Stop.

Ex. No: 23 SINGLY LINKED LIST

Date:

AIM:

To write a C program to implement singly linked list.

ALGORITHM:

Step 1: Start

Step 2: Creation: Get the number of elements, and create the nodes having structures

DATA,LINK and store the element in Data field, link them together to form a

linked list.

Step 3: Insertion: Get the number to be inserted and create a new node store the value in

DATA field. And insert the node in the required position.

Step 4: Deletion: Get the number to be deleted. Search the list from the beginning and locate

the node then delete the node.

Step 5: Display: Display all the nodes in the list.

Step 6: Stop.

Ex. No: 24 DOUBLY LINKED LIST

Date:

AIM:

To write a C program to implement doubly linked list with Insert, Delete and Display

operations.

ALGORITHM:

Step 1: Start

Step 2: Creation: Get the number of elements to create the list. Then create the node having the

Structure: BLINK, DATA , FLINK and store the elements in Data field. Link them

together to form a doubly linked list.

Step 3: Insertion: Get the number to be Inserted, create a new node to store the value. Search

the list and insert the node in its right position.

Step 4: Deletion: Get the number to be deleted. Search the list from the beginning and try to

locate node p with DATA. If found then delete the node.

Step 5: FLINK P’s previous node to P’s Next node. BLINK P’s Next node to P’s Previous node

else display “Data not Found”.

Step 6: Display: Display all the nodes in the list.

Step 7: Stop.

Ex. No: 25 STACK USING ARRAY

Date:

AIM:

To write a C program to implement Stack operations such as push, pop and display using

array.

ALGORITHM:

Step 1: Start.

Step 2: Initialy top = -1;

Step 3: push operation increases top by one and writes pushed element to storage[top];

Step 4: pop operation checks that top is not equal to -1 and decreases top variable by 1;

Step 5: display operation checks that top is not equal to -1 and returns storage[top];

Step 6: Stop.

Ex. No: 26 STACK USING LINKED LIST

Date:

AIM:

To write a C program to implement Stack operations such as push, pop and display using

linked list.

ALGORITHM:

Step 1: Start.

Step 2: push operation inserts an element at the front.

Step 4: pop operation deletes an element at the front of the list;

Step 5: display operation displays all the elements in the list.

Step 6: Stop.

.

Ex. No: 27 QUEUE USING ARRAY

Date:

AIM:

To write a C program to implement Queue operations such as enqueue, dequeue and

display using array.

ALGORITHM:

Step 1: Start.

Step 2: Initialize front=0; rear=-1.

Step 3: Enqueue operation moves a rear by one position and inserts a element at the rear.

Step 4: Dequeue operation deletes a element at the front of the list and moves the front by one

position

Step 5: Display operation displays all the element in the list.

Step 6: Stop.

Ex. No: 28 QUEUE USING LINKED LIST

Date:

AIM:

To write a C program to implement Queue operations such as enqueue, dequeue and

display using linked list.

ALGORITHM:

Step 1: Start.

Step 2: enqueue operation inserts an element at the rear of the list.

Step 4: dequeue operation deletes an element at the front of the list.

Step 5: display operation display all the element in the list.

Step 6: Stop.

Ex. No: 29 INFIX TO POSTFIX EXPRESSION USING STACK

Date:

AIM:

To write a C program to implement the conversion of infix to postfix expression using

Stack.

ALGORITHM:

Step 1: Start.

Step 2: Create a stack to store operand and operator.

Step 3: In Postfix notation the operator follows the two operands and in the infix notation the

operator is in between the two operands.

Step 4: Consider the sum of A and B. Apply the operator “+” to the operands A and B and write

the sum as A+B is INFIX. + AB is PREFIX. AB+ is POSTFIX

Step 5: Get an Infix Expression as input and evaluate it by first converting it to postfix and then

evaluating the postfix expression.

Step 6: The expressions with in innermost parenthesis must first be converted to postfix so that

they can be treated as single operands. In this way Parentheses can be successively

eliminated until the entire expression is converted.

Step 7: The last pair of parentheses to be opened with in a group of parentheses encloses the first

expression with in that group to be transformed. This last-in first-out immediately

suggests the use of Stack. Precedence plays an important role in the transforming infix to

postfix.

Step 8: Stop.

Ex. No: 30 EVALUATION OF POSTFIX EXPRESSION USING STACK

Date:

AIM:

To write a C program to implement the evaluation of postfix expression using Stack.

ALGORITHM:

Step-1: Start.

Step 2: Scan the Postfix string from left to right. 

Step 3: Initialize an empty stack. 

Step 4: If the scanned character is an operand, add it to the stack. If the scanned character is an

operator, there will be atleast two operands in the stack. 

Step 5: If the scanned character is an Operator, then we store the top most element of the

stack(topStack) in a variable temp. Pop the stack. Now evaluate

topStack(Operator)temp.

Let the result of this operation be retVal. Pop the stack and Push retVal into the stack.

Repeat this step till all the characters are scanned. 

Step 6: After all characters are scanned, we will have only one element in the stack. Return

topStack.

Step 7: Stop.

Ex. No: 31 LINEAR SEARCH

Date:

AIM:

To write a C program to implement the concept of linear search.

ALGORITHM:

Step 1: Start with the first item in the list.

Step 2: Compare the current item to the target

Step 3: If the current value matches the target then we declare victory and stop.

Step 4: If the current value is less than the target then set the current item to be the next item and

repeat from 2.

Step 5: Stop.

Ex. No: 32 BINARY SEARCH

Date:

AIM:

To write a C program to implement the concept of binary search.

ALGORITHM:

Step 1: Set the list to be the whole list

Step 2: Find the middle value of the list

Step 3: If the middle value is equal to the target then we declare victory and stop.

Step 4: If the middle item is less than the target, then we set the new list to be the upper half of

the old list and we repeat from step 2 using the new list.

Step 5: If the middle value is greater than the target, then we set the new list to be the bottom

half

of the list, and we repeat from step 2 with the new list.

Step 6: Stop.

Ex. No: 33 BUBBLE SORT

Date:

AIM:

To write a C program to implement the concept of bubble sort.

ALGORITHM:

Step 1: Start.Step 2: Repeat Steps 3 and 4 for i=1 to 10 Step 3: Set j=1 Step 4: Repeat while j<=n          (A) if  a[i] < a[j]              Then interchange a[i] and a[j]              [End of if]          (B) Set j = j+1        [End of Inner Loop]     [End of Step 1 Outer Loop] Step 5: Stop.

Ex. No: 34 MERGE SORT

Date:

AIM:

To write a C program to implement the concept of merge sort.

ALGORITHM:

Step 1: Start.

Step 2: First you divide the number of elements by 2 and seperate them as two.

Step 3: Divide those two which are divided by 2.

Step 4: Divide them until you get a single element.

Step 5: Start comparing the starting two pair of elements with each other and place them in

ascending order.

Step 6: When you combine them compare them so that you make sure they are sorted.

Step 7: When all the elements are compared the array will be surely sorted in an ascending order.

Step 8: Stop.

Ex. No: 35 QUICK SORT

Date:

AIM:

To write a C program to implement the concept of Quick sort.

ALGORITHM:

Step 1: Start.

Step 2: Choose any element of the array to be the pivot.

Step 3: Divide all other elements (except the pivot) into two partitions.

o All elements less than the pivot must be in the first partition.

o All elements greater than the pivot must be in the second partition.

Step 4: Use recursion to sort both partitions.

Step 5: Join the first sorted partition, the pivot, and the second sorted partition.

Step 6: Stop.