CS501 · Practice
16 hands-on coding problems, one or two per module. Try to solve each one yourself before checking the hint or solution.
Your progress
0 of 16 problems solved
Programming basics, algorithms, language processors, data types.
Write a program that declares a string variable with your name and prints "Hello, <name>!" to the console.
Write pseudocode (step-by-step algorithm) to find the largest of two numbers entered by the user, then implement it in C++.
Expressions, operators, if/else and switch decisions.
Take an integer input and print whether it is even or odd using the modulus operator.
Given marks (0-100), print a letter grade: A (>=90), B (>=80), C (>=70), D (>=60), F (below 60). Use if/else if.
for, while, do…while, random numbers and nested loops.
Take an integer N and print the sum of all numbers from 1 to N using a for loop.
Print the multiplication table (1 to 10) for a number entered by the user using a while loop.
Write a program that checks whether a given number is prime, using a for loop and break.
1D and 2D arrays plus common array tasks.
Given an array of 5 integers, find and print the largest element.
Implement bubble sort to sort an array of integers in ascending order, then print the sorted array.
Defining, calling and passing values to functions.
Write a function `int factorial(int n)` that returns n! and call it from main for a user-entered number.
Write a function `void swapNums(int &a, int &b)` that swaps two numbers using pass by reference, and demonstrate it in main.
Recursive thinking and working with character arrays.
Write a recursive function `int fib(int n)` that returns the nth Fibonacci number.
Write a program that checks whether a given string reads the same forwards and backwards.
User-defined types and persistent file I/O.
Define a `struct Student` with name, roll number, and marks. Create one student, fill in the values, and print them.
Write a program that writes "Hello File" into a file called data.txt, then reads and prints it back.
Refactoring techniques to keep code clean.
Refactor this poorly-named, hard-to-read function to use clear variable names and consistent formatting, while keeping the same behavior (sums even numbers from 1 to n): int f(int x){int s=0;for(int i=1;i<=x;i++){if(i%2==0){s=s+i;}}return s;}