Category Archives: C/C++ Puzzles

Precision of floating point numbers in C++ (floor(), ceil(), trunc(), round() and setprecision())

Decimal equivalent of 1/3 is 0.33333333333333…. An infinite length number would require infinite memory to store, and we typically have 4 or 8 bytes. Therefore, Floating point numbers store only a certain number of significant digits, and the rest are lost. The precision of a floating point number defines how many significant digits it can… Read More »

Structure Sorting (By Multiple Rules) in C++

Prerequisite : Structures in C Name and marks in different subjects (physics, chemistry and maths) are given for all students. The task is to compute total marks and ranks of all students. And finally display all students sorted by rank. Rank of student is computed using below rules. If total marks are different, then students… Read More »

C++ bitset interesting facts

Bitset is a container in C++ Standard Template Library for dealing with data at the bit level. A bitset stores bits (elements with only two possible values: 0 or 1). We can however get the part of a string by providing positions to bitset constructor (Positions are with respect to string position from left to… Read More »

<bits/stdc++.h> in C++

It is basically a header file that includes every standard library. In programming contests, using this file is a good idea, when you want to reduce the time wasted in doing chores; especially when your rank is time sensitive. In programming contests, people do focus more on finding algorithm to solve a problem than on… Read More »

std::string class in C++

C++ has in its definition a way to represent sequence of characters as an object of class. This class is called std:: string. String class stores the characters as a sequence of bytes with a functionality of allowing access to single byte character. std:: string vs Character Array A character array is simply an array… Read More »