A2610008 - COMPUTATIONAL THINKING AND
PROBLEM SOLVING USING C LAB
Course Outcomes: At the end of this course, the student will be able to
CO1 : Apply computational thinking to construct algorithms and flowcharts for a
given problem and translate them into working C programs. Apply - K3
CO2: Develop C programs using operators, selection statements and loops to
implement a specified logic. Apply - K3
CO3: Develop C programs that manipulate arrays, strings, structures and pointers
to solve computational problems. Apply - K3
CO4: Construct modular programs using user-defined functions and recursion and
perform file input-output operations. Apply - K3
CO5: Analyse a C program by tracing and debugging it and evaluate alternative
implementations for correctness and efficiency.
Analyze – K4
Lab Requirements (tools / software to carry out the experiments):
- C compiler: GCC (GNU Compiler Collection) — via MinGW-w64 on Windows, or the built-in gcc
on Linux/macOS.
- IDE / editor: Code::Blocks, Dev-C++ or Visual Studio Code with the C/C++ extension.
Command-line terminal to compile and run programs (gcc, ./a.out) and observe the compile–link–run
stages.
- Debugger: GDB (GNU Debugger), integrated in Code::Blocks / VS Code, for tracing and step-by
step debugging.
- Operating system: Windows 10/11 or a Linux distribution (e.g., Ubuntu); any 64-bit PC with 4 GB
RAM or more.
- No-install alternative: OnlineGDB, Programiz or Replit for quick practice and testing in a browser.
Getting Started with
1. Write, compile and run a C program that prints “Hello, World!” on the screen. Identify the source file,
the object file and the executable produced, and record the command used at each stage.
2. Write a C program that declares variables of type int, float, char and double, reads a value for each from
the user, and displays each value together with the size of its type using sizeof.
3. Write a C program to read the height and width of a rectangle from the user and compute its perimeter
and area.
1. Write a C program to compute the distance between two points whose coordinates are entered by the
user.
2. Write a C program that reads four integers p, q, r, s and, using relational and logical operators, prints
'Correct values' if q > r, s > p and (r + s) > (p + q); otherwise 'Wrong values'.
3. Write a C program to compute simple and compound interest for values entered by the user.
1. Write a C program to read a character and classify it as a vowel, consonant, digit or special symbol.
2. Write a C program to find the largest of three numbers using nested if-else.
3. Write a menu-driven C program to compute the area of various geometrical shapes (circle, rectangle,
triangle, square) using switch-case.
1. Write a C program to display the first n even natural numbers and their sum.
2. Write a C program to reverse a given integer and check whether it is a palindrome.
3. Write a C program to display the sum of the harmonic series 1 + 1/2 + 1/3 + ... up to n terms.
1. Write a C program to print the multiplication table pyramid for numbers 1 to n using nested loops.
2. Write a C program to check whether a given number is prime, then extend it to print all prime numbers
and all Armstrong numbers below.
1. Write a C program to print all unique elements of an array, and implement linear search to find a given
element in the array.
2. Write a C program to separate the odd and even elements of an array into two different arrays, and
implement binary search to find a given element in a sorted array.
3. Write a C program to sort the elements of an array in ascending order using selection sort, and compare
the efficiency of linear search vs. binary search on the sorted array by counting the number of
comparisons each method takes.
1. Write a C program to perform addition of two square matrices and display the resultant matrices.
2. Write a C program to multiply two square matrices and display the resultant matrices.
3. Write a C program to find the transpose of a given matrix.
Exercise 8: Strings:
Write C programs to perform the following without using string handling functions
- Find the length of a given string.
- Copy one string into another.
- Concatenate two strings.
- Compare two strings and display whether they are equal, or which one is greater.
- Reverse a given string (using a separate swap function to exchange characters).
- Search for a character in a string and display its position (or indicate if not found).
- Count the number of vowels, consonants, and words in a given string
Exercise 9: Pointers Fundamentals
1. Write a C program to demonstrate the use of the & (address-of) and * (value-at-address) operators.
2. Write a C program to add two numbers using pointers.
3. Write a C program to swap two values using call by reference.
Exercise 10: Pointers and Dynamic Memory
1. Write a C program to dynamically allocate memory for an array using malloc, find the largest
element and the sum of all elements in it, then repeat using calloc and note the difference between
the two.
2. Write a C program to count the number of vowels in a string using a pointer.
Exercise 11: User-Defined Functions
1. Write a C program to check whether a number is prime using a user-defined function.
2. Write a C program to compute the GCD and LCM of two numbers using functions.
3. Write a C program to demonstrate a function that returns a pointer.
Exercise 12: Recursion
1. Write a C program to compute the factorial and the n-th Fibonacci term using recursion.
2. Write a C program to compute the sum of digits of a number using recursion.
3. Write a C program to convert a decimal number to its binary equivalent using a recursive function.
Exercise 13: File Handling
1. Write a C program to append multiple lines at the end of an existing text file.
2. Write a C program to copy the contents of one file into another file.
3. Write a C program to count the number of characters, words and lines in a text file.
E-RESOURCES:
1. NPTEL – Programming in C, IIT Kanpur: https://onlinecourses.nptel.ac.in/noc21_cs81/preview
2. Virtual Labs – Problem Solving Lab, IIIT Hyderabad: https://ps-iiith.vlabs.ac.in/
3. GeeksforGeeks – C Programming: https://www.geeksforgeeks.org/c-programming-language/
No comments:
Post a Comment