Category Archives: C/C++ Puzzles

Loops in C++

Loops in programming comes into use when we need to repeatedly execute a block of statements. For example: Suppose we want to print “Hello World” 10 times. This can be done in two ways as shown below: Iterative Method Iterative method to do this is to write the printf() statement 10 times. Using Loops In… Read More »

A creative C++ program to Zoom digits of an integer

Write a C (or C++) program to ZOOM (magnify) the digits of an integer. It should take an integer from the user and display each digit of the integer in magnified form using some pattern. Examples: Input : 123 Output : @ @@ @ @ @@@@@ ——————————- @@@@ @ @ @ @ @@@@ ——————————- @@@@@… Read More »

Variadic function templates in C++

Variadic templates are template that take a variable number of arguments. Variadic function templates are functions which can take multiple number of arguments. Syntax for a variadic function template: : template(typename arg, typename… args) return_type function_name(arg var1, args… var2) Note :, typename arg, typename… args must be inside angular brackets. Below is an example in… Read More »

Raw string literal in C++

In C++, to escape characters like “\n” we use an extra “\”. From C++ 11, we can use raw strings in which escape characters (like \n \t or \” ) are not processed. The syntax of raw string is that the literal starts with R”( and ends in )”. Let’s see an an example to… Read More »

Chrono in C++

Chrono library is used to deal with date and time. This library was designed to deal with the fact that timers and clocks might be different on different systems and thus to improve over time in terms of precision. The unique thing about chrono is that it provides a precision-neutral concept by separating duration and… Read More »

std:: valarray class in C++

C++98 introduced a special container called valarray to hold and provide mathematical operations on arrays efficiently. It supports element-wise mathematical operations and various forms of generalized subscript operators, slicing and indirect access. As compare to vectors, valarrays are efficient in certain mathematical operations than vectors also. Public member functions in valarray class : 1. apply()… Read More »

memset() in C with examples

memset() is used to fill a block of memory with a particular value. The syntax of memset() function is as follows : // ptr ==> Starting address of memory to be filled // x ==> Value to be filled // n ==> Number of bytes to be filled starting // from ptr to be filled… Read More »

C++ Floating Point Manipulation (fmod(), remainder(), remquo() … in cmath)

Like integers, C++11 introduced some basic inbuilt functions for handling simple mathematical computations of floating point numbers necessary for day to day programming as well as competitive programming. This article discusses some of the functions introduced. 1. fmod() : This function is used to return the remainder(modulus) of 2 floating point numbers mentioned in its… Read More »

C/C++ program to shutdown a system

How to shutdown your computer in Linux and/or Windows? The idea is to use system() in C. This function is used to invoke operating system commands from C program. Linux OS:   Windows OS: This article is contributed by Sahil Chhabra (KILLER). If you like GeeksforGeeks and would like to contribute, you can also write… Read More »