Server Side Programming Articles - Page 2158 of 2650

Almost Perfect Number in C++

Manisha Chand
Updated on 31-Jul-2025 15:23:45

255 Views

Almost Perfect Number in C++ Almost Perfect Number is a positive integer n for which the sum of all its positive proper divisors (excluding the number itself ) is equal to n-1. (i.e., one less than the number n). It is also known as the least deficient number or slightly defective number. A positive proper divisor is a divisor of a number, excluding the number itself. For example, for n = 6; 1, 2, 3 are positive proper divisors but 6 itself is not. In Mathematics, we say A number n is almost perfect if: σ(n)-n = n-1 by ... Read More

Allocate minimum number of pages in C++

sudhir sharma
Updated on 16-Oct-2019 07:18:39

499 Views

Allocate a minimum number of pages is a programming problem. Let's discuss this problem in detail and see what can be the solution to it.StatementYou are given the number of pages of n different books. Also, there are m students to whom the books are to be assigned. The books are arranged in ascending order of the number of pages. And every student can be assigned some consecutive books. The program should return the maximum number of pages read by a student which should be minimum.Let's take an example to understand this problem in a better way, Input : books[] ... Read More

Arc function in C

sudhir sharma
Updated on 16-Oct-2019 07:12:56

3K+ Views

In the C programming language, there is an option to create an arc of a circle of a given radius with a given center coordinates and degree of the arc.The arc() function is used to create an arc. This arc function is included in graphics.h library in C which contains methods that can draw figures on the output screen.Syntaxvoid arc(int x, int y, int startangle, int endangle, int radius);Now, let's get deep into the function and understand each parameter passed and output returned by the function.Parametersx − type = int, function: defines the x coordinate of the center of the arc.y ... Read More

Alternate Fibonacci Numbers in C++

Nishu Kumari
Updated on 04-Aug-2025 16:24:15

729 Views

The Fibonacci sequence starts from 0 and 1, and each number is the sum of the previous two. In this problem, we are given a number n, and we need to print the first n numbers from the Fibonacci series, but only the numbers at alternate positions (like 0th, 2nd, 4th, and so on). Let's look at some example scenarios to understand it clearly: Scenario 1 Input: n = 7 Output: 0 1 3 8 Explanation: The first 7 Fibonacci numbers are 0 1 1 2 3 5 8. If we pick alternate numbers (index 0, 2, ... Read More

Alignof operator in C++

Akansha Kumari
Updated on 22-Aug-2025 15:22:29

792 Views

C++ alignof() Operator The alignof operator is the operator that returns the memory alignment for a given variable type. This alignment tells how the data is arranged and accessed in memory. It returns the value in bytes and is the part of the header file in C++. which is mainly used for low-level programming like memory management or hardware requirements. Syntax Here is the following syntax of alignof operator, which returns memory alignment required for a given data type in bytes: alignof(data_type) Example Demonstrating Usage of alignof() Operator Here is the following example code of using alignof() operator ... Read More

Advanced master theorem for divide and conquer recurrences

sudhir sharma
Updated on 08-Jun-2020 05:44:13

2K+ Views

Divide and conquer is an algorithm that works on the paradigm based on recursively branching problem into multiple sub-problems of similar type that can be solved easily.ExampleLet’s take an example to learn more about the divide and conquer technique −function recursive(input x size n)    if(n < k)       Divide the input into m subproblems of size n/p.       and call f recursively of each sub problem    else       Solve x and returnCombine the results of all subproblems and return the solution to the original problem.Explanation − In the above problem, the problem ... Read More

Virtual Copy Constructor in C++

sudhir sharma
Updated on 16-Oct-2019 06:32:23

7K+ Views

Before digging deep into the topics lets brush up all the related terms.A copy constructor is a special type of constructor that is used to create an object that is an exact copy of the object that is passed.A virtual function is a member function that is declared in the parent class and is redefined ( overridden) in a child class that inherits the parent class.With the use of a virtual copy constructor, the programmer will be able to create an object without knowing the exact data type of the object.In C++ programming language, copy Constructor is used to creating ... Read More

C/C++ Pointer Puzzle?

sudhir sharma
Updated on 07-Oct-2019 08:19:16

446 Views

A Pointer is a variable that stores the address of another variable. The data type of the pointer is the same as the data type as the variable.In this puzzle you need to know the size of the pointer that is being used. The puzzle checks our understanding of pointers by asking you the size of variable.The size of int is 4 bytes, whereas the size of int pointer is 8. Now, let’s test your skills with the following exercise in c++ programming language.Example Live Demo#include using namespace std; int main() {    int a = 6 ;    int ... Read More

C/C++ Function Call Puzzle?

sudhir sharma
Updated on 07-Oct-2019 08:14:43

242 Views

This C/C++ function call puzzle is a puzzle that is intended to explore more about the behaviour of method calling in both the programming languages C and C++/.The output of a method in C and C++ is different. Lets see what is the difference in calling methods in C and C++.Let’s take an example and check the output of the below code in c and c++.Example Live Demovoid method() {    // Print statement } int main() {    method();    method(2); }OutputFor C++ −Error : too many arguments to function ‘void method()’For C −Program runs without any error.Logic behind the ... Read More

C++ Boolean Matrix

sudhir sharma
Updated on 07-Oct-2019 08:12:21

1K+ Views

Boolean matrix is a matrix that has only two elements 0 and 1. For this boolean Matrix question, we have a boolean matrix arr[m][n] of size mXn. And the condition to solve is, if m[i][j] = 1 then m[i] = 1 and m[j] = 1 which means all elements of the ith row and jth column will become 1.Let’s take an example, Input: arr[2][2] = 1 0                   0 0 Output: arr[2][2] = 1 1                   1 0Explanation− arr[0][0] = 1 ... Read More

Advertisements