Category Archives: C/C++ Puzzles

Inbuilt library functions for user Input | scanf, fscanf, sscanf, scanf_s, fscanf_s, sscanf_s

scanf() : The C library function int scanf (const char *format, …) reads formatted input from stdin. Syntax: int scanf(const char *format, …) int: return type format: string that contains the type specifier(s) “…” (ellipsis): indicates that the function accepts a variable number of arguments Each argument must be a memory address where the converted… Read More »

Write a URL in a C++ program

Writing URLs in a C++ code doesn’t affect the program and the compiler will not throw any error. Output: This code is error free This code is error free This code is error free This code is error free This code is error free Explanation: Any identifier followed by a : becomes a (goto) labels… Read More »

Complex numbers in C++ | Set 1

The complex library implements the complex class to contain complex numbers in cartesian form and several functions and overloads to operate with them. real() – It returns the real part of the complex number. imag() – It returns the imaginary part of the complex number. Output: Real part: 10 Imaginary part: 2 abs() – It… Read More »

Printing Heart Pattern in C

How to print below heart pattern in C? AAAAAAA AAAAAA AAAAAAAAA AAAAAAAA AAAAAAAAAAA AAAAAAAAAA AAAAAAAAAAAAA AAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAA BBBBBBBBBBBBBBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBB BBBBBBBBBBBBB BBBBBBBBBBB BBBBBBBBB BBBBBBB BBBBB BBB B This is code to print the Heart pattern using simple C logic Output : AAAAAAA AAAAAA AAAAAAAAA AAAAAAAA AAAAAAAAAAA AAAAAAAAAA AAAAAAAAAAAAA AAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAA… Read More »

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 »