Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
25 views

Programming in C Practice Book - Module 2

Nothing
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Programming in C Practice Book - Module 2

Nothing
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 119

24CS101 PROGRAMMING IN C

Practice Book

Module - 2

Roll No: ……………………………………………………………………………………..

Name: ……….……………………………………………………………………………….

Branch & Section: ……..………….……………………………………………………

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


VIGNAN’S FOUNDATION FOR SCIENCE, TECHNOLOGY & RESEARCH
VADLAMUDI, GUNTUR
1. Write an algorithm, flowchart and program that creates an array of integers of size 5 and performs I/O
operations on it with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 1


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 2


2. Write an algorithm, flowchart and program that finds the sum and average of a given list of integers using
a one-dimensional array with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 3


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 4


3. Write an algorithm, flowchart and program to find the largest of a given list of integers using a one-
dimensional array with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 5


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 6


4. Write an algorithm, flowchart and program to find the smallest of a given list of integers using a one-
dimensional array with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 7


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 8


5. Write an algorithm, flowchart and program to generate the first n terms of the Fibonacci series using a
one-dimensional array with possible test cases.

Logic:

Flowchart:

Algorithm:

Department of Computer Science & Engineering 9


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 10


6. Write an algorithm, flowchart and program to sort a given list of integers in ascending order using a 1-D
array with possible test cases.

Logic:
Flowchart:

Algorithm:

Department of Computer Science & Engineering 11


Program : Tracing program with Testcases/Output:

Department of Computer Science & Engineering 12


7. Write an algorithm, flowchart and program to demonstrate passing of every 1-D array element by value
to a function with possible test cases.

Logic:

Flowchart:
Algorithm:

Department of Computer Science & Engineering 13


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 14


8. Write an algorithm, flowchart and program that demonstrate passing of 1-D array elements by reference
to a function with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 15


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 16


9. Write an algorithm, flowchart and program that demonstrates passing of entire 1-D array to a user-
defined function where the corresponding formal argument is a sized array with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 17


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 18


10. Write an algorithm, flowchart and program that demonstrates passing of entire 1-D array to a user-
defined function where the corresponding formal arguments is an unsized array with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 19


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 20


11. Write an algorithm, flowchart and program that demonstrates pointer arithmetic with possible test
cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 21


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 22


12. Write an algorithm, flowchart and program that demonstrates passing of entire 1-D array to a user-
defined function. (plain pointer) with possible test cases.

Logic:

Flowchart:
Algorithm:

Department of Computer Science & Engineering 23


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 24


13. Write an algorithm, flowchart and program that performs I/O operations for a 1-D array using the
following user-defined functions.
a. read() – to read a list into an array.
b. display()- to display the list.

Logic:

Flowchart:
Algorithm:

Department of Computer Science & Engineering 25


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 26


14. Write an algorithm, flowchart and program to find the largest of a given list of integers using a
1-D array and the following user-defined functions.
a. read() – to read a list into an array.
b. display()- to display the list.
c. largest()- to return the largest of the list.

Logic:

Flowchart:

Algorithm:

Department of Computer Science & Engineering 27


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 28


15. Write an algorithm, flowchart and program to print the first n terms of the Fibonacci terms using
the user-defined function called genfibo() with possible test cases.

Logic:

Flowchart:
Algorithm:

Department of Computer Science & Engineering 29


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 30


16. Write an algorithm, flowchart and program that finds the second largest and second smallest
values in a given list of integers using the following user-defined functions.
a. read()- to read a list into an array.
b. smallest_largest()- to find the second smallest and largest values.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 31


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 32


17. Write an algorithm, flowchart and program that creates a 1-D array and performs the following
operations on it using user-defined functions.
a. Read()- to input the list
b. Display()- to display a list
c. Insert()- to insert a value at a specified location
d. Delete()- to delete an element from a specified location
e. Duplicate()- to remove the duplicate values from the list.

Logic:
Flowchart:

Algorithm:

Department of Computer Science & Engineering 33


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 34


18. Write an algorithm, flowchart and program that creates a 1-D array of integers of size 10 and
perform I/O operations using pointer notations with possible test cases.

Logic:

Flowchart:

Algorithm:

Department of Computer Science & Engineering 35


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 36


19. Write an algorithm, flowchart and program to find the largest of a given list of integers using a
1-D array and pointer notations with possible test cases.

Logic:

Flowchart:

Algorithm:

Department of Computer Science & Engineering 37


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 38


20. Write an algorithm, flowchart and program to find the largest of a given list of integers using a 1-
D array and the following user-defined functions.
a. read() – to read a list into an array.
b. largest()- to return the largest of the list.

Use pointer notations wherever possible.

Logic:
Flowchart:

Algorithm:

Department of Computer Science & Engineering 39


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 40


21. Write an algorithm, flowchart and program to sort a given list of integers using a 1-D array the
following user-defined functions.
a. read() – to read a list into an array.
b. display()- to display the list.
c. sort()- to sort the values in ascending order.
Use Pointer notations wherever possible.

Logic:
Flowchart:

Algorithm:

Department of Computer Science & Engineering 41


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 42


22. Write a program that creates a 1-D array dynamically and performs I/O operations on it.

Logic:

Flowchart:
Algorithm:

Department of Computer Science & Engineering 43


Program Code: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 44


23. Write an algorithm, flowchart and program that demonstrates the strlen() function.

Logic:

Flowchart:

Algorithm:

Department of Computer Science & Engineering 45


Program Code: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 46


24. Write a function that finds the length of a string, call it xstrlen(). Test the function with possible
test cases.

Logic: Flowchart:

Algorithm:

Department of Computer Science & Engineering 47


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 48


25. Write an algorithm, flowchart and program that demonstrates the strcpy() function with
possible test cases.

Logic:

Flowchart:

Algorithm:

Department of Computer Science & Engineering 49


Program: Tracing program with Test cases/Output:

Department of Computer Science & Engineering 50


26. Write a function that duplicates strcpy() function, call it xstrcpy() and execute it with all
possible test cases.

Logic:

Flowchart:

Algorithm:

Department of Computer Science & Engineering 51


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 52


27. Write an algorithm, flowchart and program to demonstrate the strcat() function with possible
test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 53


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 54


28. Write a function that duplicates the strcat() function, call it xstrcat(). Test the function with
possible test cases.

Logic:

Flowchart:
Algorithm:

Department of Computer Science & Engineering 55


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 56


29. Write a function that duplicates strcmp() function, call it xstrcmp(). Test the function with
possible test cases.

Logic:

Flowchart:
Algorithm:

Department of Computer Science & Engineering 57


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 58


30. Write a function that duplicates strrev() function, call it xstrrev(). Test the function with
possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 59


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 60


31. Write an algorithm, flowchart and program to create a 2-D array of integers with 3 rows and 2
columns and perform I/O operations on it with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 61


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 62


32. Write an algorithm, flowchart and program that demonstrates passing of an entire 2-D array to
user-defined function (sized array) with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 63


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 64


33. Write an algorithm, flowchart and program to find the sum of two matrices using 2-D arrays
and the following user-defined functions.
1. Matinput()-to read matrix
2. Matoutput()-to display the matrix
3. Matadd()-to add two matrices.

Logic:

Flowchart:

Algorithm:

Department of Computer Science & Engineering 65


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 66


34. Write an algorithm, flowchart and program to find the trace of a matrix with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 67


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 68


35. Write an algorithm, flowchart and program to verify whether a given matrix is symmetric or not
with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 69


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 70


36. Write an algorithm, flowchart and program to find the row sums and column sums of a matrix
with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 71


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 72


37. Write an algorithm, flowchart and program to check whether a matrix is an upper triangular
matrix with possible test cases.
Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 73


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 74


38. Write an algorithm, flowchart and program to check whether a matrix is an lower triangular
matrix with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 75


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 76


39. Write an algorithm, flowchart and program that finds the transpose of a given matrix using the
following user-defined functions
1. Matinput()- to input the matrix
2. Matouput()-to display the matrix
3. Transpose()-to transpose the matrix

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 77


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 78


40. Write a program that multiplies two matrices using 2-D arrays and the following user-defined functions.
a. Matinput() ==> to read input for the matrix
b. Matmultiply() ==> to multiply two matrices
c. Matoutput() ==> to display the matrix
Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 79


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 80


41. Write an algorithm, flowchart and program that creates a 2-D array of integers and performs
I/O operations on it using pointer notations with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 81


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 82


42. Write an algorithm, flowchart and program to sort a given list of names in alphabetical order
using a character 2-D array with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 83


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 84


43. Write a program that creates a 2-D array dynamically and perform I/O operations on it.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 85


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 86


44. Write a program that finds the product of two matrices using dynamically created 2-D arrays and the
following user-defined functions.
a. Matinput() ==> to read input for the matrix
b. Matmultiply() ==> to multiply two matrices
c. Matoutput() ==> to display the matrix.
Logic:

Flowchart:

Algorithm:

Department of Computer Science & Engineering 87


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 88


45. Create a structure called complex and includes the following members.
a. X type float represent the real part of a complex number.
b. Y type float  represent the imaginary part of a complex number.

Create a variable of type complex and perform I/O operations on it with possible test cases.

Logic:

Flowchart:

Algorithm:

Department of Computer Science & Engineering 89


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 90


46. Create a structure called book and include the following members.
a. Title type char size 40 represents the title of the book, a string.
b. Pages type int represents the number pages in the book, an integer.
c. Price type float represents the price of the book, a float value.
Create a variable of type book and perform I/O operations on it

Logic:

Flowchart:

Algorithm:

Department of Computer Science & Engineering 91


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 92


47. Create a structure called student and include the following members.
a. Regdno type int  represents the register number of a student
b. Name tyoe char size 40 represents the name of the student
c. Maths type int represents the marks in maths subject
d. Physics type int represents the marks in physics subject
e. Chemistry type int represents the marks in chemistry subject
f. Total type int  represents the total of maths, physics and chemistry.
g. Percentage type float represents the percentage of marks obtained
h. Results type char size 5 represents the results of the student, that is “PASS” or
“FAIL”.

Note: Assume that, a student has to get a minimum of 50 marks in every subject to pass the
examination.

Create an array of structures of type student and computerize the results of a given list of
students.

Logic:

Flowchart:

Algorithm:

Department of Computer Science & Engineering 93


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 94


48. Write an algorithm, flowchart and program that demonstrates the nested structures with
possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 95


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 96


49. Write an algorithm, flowchart and program to create a new data type called student using
typedef with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 97


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 98


50. Write an algorithm, flowchart and program that creates a text file and writes lines of text into
the file with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 99


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 100


51. Develop an an algorithm and program to count number of characters, words and lines in a text
file.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 101


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 102


52. Develop an an algorithm, flowchart and program to find occurrence of a word in file.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 103


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 104


53. Create a file called “numbers.dat” and write all integers from 1 to 10 into the file.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 105


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 106


54. Develop an algorithm, flowchart and program that does the following
a. Read the contents of the file “numbers.dat” created by the previous program.
b. Write all the even integers into a file “even.dat” and all the odd numbers into the file
“odd.dat”.
c. Display the contents of “even.dat” and “odd.dat” files.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 107


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 108


55. Create a structure called employee and includes the following members
a. Name type char and size 34
b. Idno type int
c. Salary type float
Create a file called “employee.dat” and write the data of a list of employees into the file. Use
the structure employee to store the data.
Illustrate the fprintf() and fwrite() functions to write the data into the file separately.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 109


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 110


56. Develop an an algorithm, flowchart and program that read the data from the file
“employee.dat” created by the previous program use appropriate structure to represent the
employee data with possible test cases.
Illustrate the fscanf() and fread() functions to write the data into the file separately.
Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 111


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 112


57. Assuming that the file “employee.dat” already exists. Write an algorithm, flowchart and
program to count the number of records in the file. Also display the information of a specific
record in the file.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 113


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 114


58. Write an algorithm, flowchart and program to display the contents of a text file onto the screen
with possible test cases.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 115


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 116


59. Write an algorithm, flowchart and program that copies the contents of one into another.

Logic:

Algorithm: Flowchart:

Department of Computer Science & Engineering 117


Program: Tracing program with Testcases/Output:

Department of Computer Science & Engineering 118

You might also like