Coding 2024 25 Final
Coding 2024 25 Final
Week
Week 1
Week 2
Week 3
Week 4
Week 5
Week 6
Week 7
Week 8
Week 9
Week 10
Week 11
Week 12
Week 13
Week 14
GITAM School of Technology
Department of Computer Science and Engineering
week-wise plan for the coding classes
Semester - VII
Topics to be covered
Functions:
Introduction to Functions
Function Declaration, Definition, and Calling
Scope and Lifetime of Variables
Recursion
Inline Functions
Storage Classes: auto, extern, static, register
Arrays and Strings:
Introduction to Arrays
Single-Dimensional Arrays
Multidimensional Arrays
Strings in C
String Handling Functions
Array of Strings
Arrays and Strings:
Introduction to Arrays
Single-Dimensional Arrays
Multidimensional Arrays
Strings in C
String Handling Functions
Array of Strings
"Pointers:
Introduction to Pointers
Pointer Arithmetic
Pointers and Arrays
Pointers and Strings
Pointers to Pointers
Dynamic Memory Allocation: malloc, calloc, realloc, free
File Handling:
File Operations: Opening, Closing, Reading, Writing
Modes of File Opening
File Pointers
Reading and Writing Binary Files
File Positioning: fseek, ftell, rewind
Error Handling in File Operations
Preprocessor Directives:
Introduction to Preprocessor Directives
Macro Substitution
File Inclusion
Conditional Compilation
Other Preprocessor Directives: #define, #undef, #ifdef, #ifndef, #endif
Data Structures:
Linked Lists: Single, Double, Circular
Operations on Linked Lists: Insertion, Deletion, Traversal
Stacks and Queues: Implementation using Arrays and Linked Lists
Operations on Stacks and Queues
Code review
ineering
Practice Exercises
1) Remove an element: Given an integer array arr and an integer key, write a program in C to return the number of va
key.
2) Remove duplicates from a given array: Given a sorted integer array arr, write a program in C to return the array af
duplicates, with all the other elements in place.
3) Best time to sell a commodity: Given an array of positive integers that represent the price of a commodity on a give
integers which represent the best day to buy and later, sell the commodity.
4) Merging the strings: Given two strings str1 and str2 in two files file1 and file2, write a program to create a third str
character from each array alternatively. If one string is longer than the other, append the extra characters to str3. Write
different text file called file3.
5) String reversal: Given an string with words separated by empty spaces, commas or fullstops, write a program to ret
removing the commas and fullstops and reversing the words in the string.
6) Move all zeros to the end: Given an integer array arr, return the array with all the zeros moved to the end of the arr
ordering of the non-zero lements should not change.
7) Is substring: Given two strings str1 and str2, write a program to return true if str2 is a substring of str1 and false oth
8) Is subsequence: Given two strings str1 and str2, write a program to return true if str2 is a subsequence of str1 and f
9) Maximum value subarray: Given an array of integers arr, return the maximum sum of a subarray (with contiguous
array.
10) Single occurence of a number: Given an array of integers which all numbers but one occuring twice, find the num
only once.
1) Reverse a linked list: Given a linked list, reverse the linked lst and return the pointer to the reversed list.
2) Remove fullstops from a string: Given a string with alphanumeric characters and fullstops, write a program to remo
from the string.
3) Middle of a linked list: Given a singly linked list, find the element at the middle of the linked list.
4) Maximum odd-even sum of a linked list: Given a linkedlist, find the maximum sum sum of pairs of alternate eleme
Week 1 to 9:
Suggested List of Experiments (The teacher may discuss one or two in the class, and give5-6 problems as takeaway exercises inclu
1 Conversion of numbers from decimal to binary or hexadecimal number systems and vice versa.
2 Design a flowchart for a program that takes two numbers as input from the user and then performs the following operati
Add the two numbers.
Subtract the second number from the first number.
Multiply the two numbers.
Divide the first number by the second number (ensure to handle division by zero).
The flowchart should include decision points to handle division by zero and should clearly illustrate the flow of the progr
3 Design a flowchart for a program that calculates the total cost of a customer's shopping cart items, including tax and an
Prompt the user to input the prices and quantities of each item they wish to purchase.
Calculate the subtotal by multiplying the price of each item by its quantity and summing up all the totals.
Apply any applicable discounts based on the total purchase amount. For example, if the total purchase amount is above
Calculate the tax on the subtotal based on a predetermined tax rate.
Add the tax to the subtotal to obtain the total cost.
Display the subtotal, any discounts applied, the tax amount, and the final total cost to the user.
You can break down the program into separate modules or functions, each responsible for a specific calculation (e.g., s
4 Identify and correct the syntactical errors in a given program (example given below) to make it compile and run correctly
#include <stdio.h>
int main() {
return 0;
5 Identify and correct the semantic errors in a given program (example given below) to make it compile and run correctly.
#include <stdio.h>
int main() {
float average;
printf("Enter three numbers: ");
average = sum / 2;
return 0;
6 Write a C program that takes an integer as input from the user and prints whether the number is positive, negative, or z
7 Write a C program to implement a simple guessing game. The program should generate a random number between 1 a
8 Write a C program to print the first 10 natural numbers (1 to 10) in reverse order, one number per line.
9 The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, usually start
Write a C program to generate the first 20 terms of the Fibonacci sequence and print them.
10 Write a C program that calculates the factorial of a given number using a separate function for the factorial calculation.
11 Write a C program to calculate the average of a set of numbers. The program should prompt the user to enter the numb
12 Write a C program that simulates a simple banking system. The program should include the following functionalities:
Deposit: Allow the user to deposit a certain amount into their account.
Withdraw: Allow the user to withdraw a certain amount from their account.
Check balance: Display the current balance in the account.
Use static variables to keep track of the total balance across all transactions. Ensure that the total balance is shared am
13 Write a C program that simulates a simple online shopping system. The program should include the following functiona
Add item to cart: Allow the user to add items to their shopping cart.
Remove item from cart: Allow the user to remove items from their shopping cart.
View cart: Display the items currently in the user's shopping cart.
Ensure that each user has their own shopping cart, and use local variables to represent the items in the cart.
14 Write a C program that simulates a simple text editor. The program should allow the user to perform the following opera
Append: Append a string to the end of the current text.
Insert: Insert a string at a specific position in the current text.
Delete: Delete a substring from the current text.
Replace: Replace a substring in the current text with another string.
Print: Print the current text.
15 Write a C program that calculates the value of a mathematical expression involving trigonometric functions and logarith
sin(x)+cos(y)/log(z)
16 Write a C program that calculates the factorial of a non-negative integer using recursion. The factorial of a non-negative
n! = n*(n-1)*(n-2)*..*3*2*1
Write a C program that implements a recursive function to generate all possible combinations of a given set of characte
For example, given the input string "ABC", the program should generate the following combinations:
ABC
ACB
BAC
BCA
CAB
CBA
17 Write a C program that defines macros for mathematical operations (e.g., addition, subtraction, multiplication, division) a
18 Write a C program that defines a function to swap the values of two integers using pointers. The program should promp
19 Write a C program that takes two nxn matrix as input from the user, calculates the product of the matrices and prints it.
20 Write a C program that takes an array of integers as input, calculates the sum and average of the elements using pointe
21 Write a C program that defines a function to count the number of vowels in a string using character pointers. The progra
22 Write a C program that defines a structure called Student to store the details of a student including name, roll number, a
23 Write a C program that defines a structure called Book to store the details of books including title, author, and price. The
24 Write a C program that defines a structure called Employee to store the details of an employee including name, ID, and
25 Write a C program that defines a typedef for a structure called Point to represent a point in 2D space. The structure sho
26 Write a C program that defines a union called Data to represent a data structure that can store either an integer or a flo
27 Given a C program, comprehend the code by doing the following.
Understand and explain what the code does.
Perform code analysis in the following manner.
Identify the purpose of the code.
Describe the input required from the user.
Explain how the code produces output.
Discuss the role of variables n, i, and j.
Describe the control flow of the nested loops.
Explain the output produced by the code for different inputs.
Sample Program 1:
#include <stdio.h>
int main() {
int n, i, j;
scanf("%d", &n);
printf("\n");
return 0;
#include <stdio.h>
int main() {
scanf("%d", &n);
scanf("%d", &arr[i]);
}
for (i = 0; i < n-1; i++) {
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
printf("\n");
return 0;
#include <stdio.h>
int main() {
int n, i, j;
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[i]);
arr[j] = arr[j+1];
arr[j+1] = temp;
printf("\n");
return 0;
}
GITAM School of Technology
Department of Computer Science and Enginnering
Week - wise plan for Coding Classes
Write a C program to implemnet the various operations on a single linked list, double
linked list and circular linked list.
Write a C program to implement the stack and queue operations using arrays and linked
lists.
wo in the class, and give5-6 problems as takeaway exercises including some in the Practice Exercises column above. In the next class, start by
handle division by zero and should clearly illustrate the flow of the program from input to output.
the total cost of a customer's shopping cart items, including tax and any applicable discounts. The program should have the following features:
s of each item they wish to purchase.
each item by its quantity and summing up all the totals.
al purchase amount. For example, if the total purchase amount is above a certain threshold, apply a percentage discount.
determined tax rate.
modules or functions, each responsible for a specific calculation (e.g., subtotal calculation, discount calculation, tax calculation), and then integrate them int
a given number using a separate function for the factorial calculation. The program should prompt the user to enter a non-negative integer, calculate its fa
set of numbers. The program should prompt the user to enter the number of elements in the set, then prompt the user to enter each element. Finally, the pr
ng system. The program should include the following functionalities:
unt into their account.
mount from their account.
ance across all transactions. Ensure that the total balance is shared among all instances of the banking system.
art, and use local variables to represent the items in the cart.
ditor. The program should allow the user to perform the following operations on a text string:
a non-negative integer using recursion. The factorial of a non-negative integer n, denoted as n!, is the product of all positive integers less than or equal to
unction to generate all possible combinations of a given set of characters. The program should take a string of characters as input and print all possible com
ematical operations (e.g., addition, subtraction, multiplication, division) and uses them to perform calculations. The program should use macros to define th
p the values of two integers using pointers. The program should prompt the user to input two integers, call the swap function to swap their values, and then
nput from the user, calculates the product of the matrices and prints it.
s as input, calculates the sum and average of the elements using pointers, and then prints the sum and average.
nt the number of vowels in a string using character pointers. The program should prompt the user to input a string, call the function to count the vowels, and
d Student to store the details of a student including name, roll number, and marks in three subjects (Physics, Chemistry, and Mathematics). The program sh
d Book to store the details of books including title, author, and price. The program should then create an array of Book structures to store the details of three
d Employee to store the details of an employee including name, ID, and salary. The program should then create a pointer to an Employee structure and allo
ructure called Point to represent a point in 2D space. The structure should have two members: x and y, representing the coordinates of the point. Then, the
ata to represent a data structure that can store either an integer or a floating-point number. Additionally, define a structure called BitField to represent a data
ing the following.
ple program 2.
ogy
d Enginnering
Classes Practice Exercises (from various platforms)
LeetCode: Given an array of integers nums and an integer target, return indices of the
two numbers such that they add up to target.
HackerRank: Diagonal Difference: Calculate the absolute difference between the sums
of the diagonals in a square matrix.
CodeChef: Life, the Universe, and Everything: Write a program that reads numbers
from input and stops processing input after reading the number 42.
Codeforces: Watermelon: Determine if a watermelon can be split into two parts, each
of which weighs an even number of kilos.
LeetCode: Given a string with characters '(', ')', '{', '}', '[', and ']', determine if it is valid.
LeetCode: Fizz Buzz: Write a program that outputs numbers from 1 to n. For multiples
of three, output
LeetCode: "Fizz";
Factorial for multiples
Trailing of five,
Zeroes: Given anoutput
integer"Buzz"; and
n, return fornumber
the multiples of both
of trailing
zeroes in n!.
HackerRank: Day of the Programmer: Given a year, find the day of the 256th day of
that year.
CodeChef: Reverse The Number: Write a function to reverse the digits of a number.
Codeforces: Beautiful Matrix: Find the minimum number of moves to bring the
number
LeetCode:1 to theSum:
Two center of aan
Given 5x5 matrix.
array of integers nums and an integer target, return the
indices of the two numbers such that they add up to target.
Codeforces: Beautiful Matrix: Find the minimum number of moves to bring the
number 1 to the center of a 5x5 matrix.
LeetCode: Swap Nodes in Pairs: Given a linked list, swap every two adjacent nodes and
return its head.
CodeChef: Farmer Feb: Given an array, find the sum of all elements at even positions.
HackerRank: Structs: Write a program to model and process data using structures.
CodeChef: Student Details: Create a structure to store student details and write
functions to manipulate the data.
Codeforces: Little Elephant and Bits: Manipulate bits within a number to achieve a
desired result.
LeetCode: Read N Characters Given Read4: Given a file and an integer n, read n
characters using a given read4 function.
HackerRank: File Processing: Implement a function to read from a file and process its
content.
CodeChef: File Reading and Writing: Read input from a file, process it, and write the
output to another file.
Codeforces:
LeetCode: Add FileTwo
Operations:
Numbers:Implement basic file of
Solve the problem operations in anumbers
adding two competitive
represented as
linked lists.
CodeChef: Macro Substitution: Use macros to optimize code for specific problems.
LeetCode: Remove Nth Node From End of List: Given a linked list, remove the nth node
from the end of the list and return its head.
HackerRank: Debugging Challenge: Solve a problem that contains intentional bugs. Use
debugging techniques to identify and fix the bugs.
CodeChef: Error Handling: Write a program that handles errors such as divide by zero or
accessing out-of-bound indices.
LeetCode: Merge Two Sorted Lists: Merge two sorted linked lists and return it as a new
sorted list.
Exercises column above. In the next class, start by discussing any doubts in the previous set.:)
rogram should have the following features:
percentage discount.
calculation, tax calculation), and then integrate them into the main program flowchart.
er is positive, check if it's even or odd and print that information as well.
pt the user to guess the number. After each guess, the program should provide feedback to the user, indicating whether the guess is too high, too low, or co
he user to enter a non-negative integer, calculate its factorial using the factorial function, and then print the result.
n prompt the user to enter each element. Finally, the program should calculate and print the average of the entered numbers using separate functions for in
mpt the user to input the values of variables and evaluate the expression. Ensure to handle error cases such as division by zero or undefined values.
he product of all positive integers less than or equal to n. The factorial of n is defined as:
a string of characters as input and print all possible combinations of those characters.
culations. The program should use macros to define the operations and then demonstrate their usage in various mathematical expressions.
s, call the swap function to swap their values, and then print the swapped values.
input a string, call the function to count the vowels, and then print the count.
Physics, Chemistry, and Mathematics). The program should prompt the user to input the details of three students, store them in an array of Student structur
an array of Book structures to store the details of three books. After storing the details, the program should print the details of all books.
hen create a pointer to an Employee structure and allocate memory for it dynamically using malloc(). After allocating memory, prompt the user to input the
d y, representing the coordinates of the point. Then, the program should create a variable of type Point and initialize it with some values. Finally, it should pr
lly, define a structure called BitField to represent a data structure that stores a set of bit-fields including a flag, an integer value, and a floating-point value. T
e guess is too high, too low, or correct. The user should continue guessing until they correctly identify the random number. Additionally, limit the number of g
rs using separate functions for input, calculation, and output. Additionally, use an external variable to keep track of the sum of the numbers.
zero or undefined values.
ical expressions.
m in an array of Student structures, and then print the details of all students.
s of all books.
ory, prompt the user to input the details of an employee using the pointer, and then print the details of the employee.
some values. Finally, it should print the coordinates of the point.
alue, and a floating-point value. Then, the program should create variables of type Data and BitField, initialize them with some values, and print their conten
m number. Additionally, limit the number of guesses to 10, and if the user exceeds this limit without guessing the correct number, display a message indica