Programming Articles

Page 1371 of 2547

fread() function in C++ program

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 987 Views

Given the task is to show the working of fread() in C++. In this article we will also look into the different parameters which are passed to fread() and what this function returns.fread() is an inbuilt function of C++ which reads a block of data from the stream. This function counts the number of objects each with the size of “size” bytes from the stream and stores them in buffer memory, then position pointer advanced by the total amount of bytes read. The amount of bytes read if successful will be size *count.Syntaxfread(void *buffer, size_t size, size_t count, FILE *file_stream);ParametersThis ...

Read More

Maximum Subarray Sum with One Deletion in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 424 Views

Suppose we have an array of integers; we have to find the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, we can say that we want to choose a subarray and optionally delete one element from it so that there is still at least one element left and the sum of the remaining elements is maximum possible. We have to keep in mind that the subarray needs to be non-empty after deleting one element. So if the input is like [1, -2, 0, 3], then the output will be 4. So ...

Read More

Count numbers from 1 to n that have 4 as a digit in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 476 Views

In this tutorial, we will be discussing a program to find the numbers from 1 to n that have 4 as a digit.For this we will be provided with a number n. Our task is to count all the numbers which have 4 as one of their digits and print it out.Example#include using namespace std; bool has4(int x); //returning sum of digits in the given numbers int get_4(int n){    int result = 0;    //calculating the sum of each digit    for (int x=1; x

Read More

fma() function in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 114 Views

Given the task is to show the working of fma() function in C++. In this article we will look into what parameters this function need and what results it will be returning.fma() is an inbuilt function of cmath header file, which accepts three parameters x, y and z and return the result x*y+z without losing the precision in any intermediate result.Syntaxfloat fma(float x, float y, float z);Ordouble fma(double x, double y, double z); Orlong double fma(long double x, long double y, long double z);Parametersx − The first element to be multiplied.y − The second element with which x is to ...

Read More

Two Sum BSTs in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 288 Views

Suppose we have two binary search trees, we have to return True iff there is a node in the first tree and a node in the second tree and sum of these nodes is a given integer target. So if the tree is like −and target is 5, then the result is true.To solve this, we will follow these steps −Define a map sdefine a method called check(), this will take node, target and nodeNumber, this will work as follows −if node is valid, then return falsecurr := value of node, req := target – currif req is present in ...

Read More

isfinite() function in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 455 Views

In this article we will be discussing the working, syntax and examples of isfinite() function in C++.isfinite() is an inbuilt function in C++ which comes under header file. isfinite() function used to check and return whether the given number is finite or not, a finite number is any floating number which is neither infinite nor NaN (Not a number).Syntaxbool isfinite(float n);orbool isfinite(double n);orbool isfinite(long double n);This function include only 1 parameter n which is the value we have to check for whether it's finite or not.Return valueThe function returns boolean value, 0(false) if the number is not finite and 1(true) ...

Read More

Longest Arithmetic Subsequence of Given Difference in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 511 Views

Suppose we have an integer array arr and an integer difference, we have to find the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence is same as the difference. So if the input is like [1, 5, 7, 8, 5, 3, 4, 2, 1] and difference is -2, then the output will be − 4, as the longest arithmetic sequence is [7, 5, 3, 1]To solve this, we will follow these steps −Define a map mn := size of array arr, set ans := 0for i ...

Read More

Binary Search Tree Iterator in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we want to make one iterator for binary tree. There will be two methods. The next() method to return the next element, and hasNext() method to return Boolean value, that will indicate that the next element is present or not. So if the tree is like −And the sequence of function calls are [next(), next(), hasNext(), next(), hasNext(), next(), hasNext(), next(), hasNext()]. The output will be [3, 7, true, 9, true, 15, true, 20, false]To solve this, we will follow these steps −There are two methods next and hasNext, The next() method will be like −curr := stack top ...

Read More

isinf() function in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 2K+ Views

In this article we will be discussing the isinf() function in C++, its syntax, working and what will be its return value.isinf() is an inbuilt function in C++ which comes under header file, the function is used to check whether the variable passed in it is infinity or not, no matter if the number is negative infinity or positive infinity. If the number is infinite the function returns a non-zero value (true) and if it is not then it passes zero (false). Also if the number is NAN then also the function will return 0.Syntaxbool isinf(float n);orbool isinf(double n); orbool ...

Read More

Design A Leaderboard in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Suppose we have to design a Leaderboard class, there are three different functions −addScore(playerId, score) − This will update the leaderboard by adding score to the given player's score. When there is no such player with given id in the leaderboard, add him to the leaderboard with the given score.top(K) − This will return the score sum of the top K players.reset(playerId) − This will reset the score of the player with the given id to 0. It is guaranteed that the player was added to the leaderboard before calling this function.Initially, the leaderboard should empty.If we perform the operations ...

Read More
Showing 13701–13710 of 25,466 articles
Advertisements