Found 7347 Articles for C++

A Product Array Puzzle in C++?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

171 Views

Here we will see one interesting problem related to array. There is an array with n elements. We have to create another array of n elements. But the i-th position of second array will hold the product of all elements of the first array except the i-th element. And one constraint is that we cannot use the division operator in this problem.If we can use the division, operation, we can easily solve this problem, by getting the product of all elements, then divide i-th element of first array and store it into i-th place of the second array.Here we are ... Read More

A product array puzzle (O(1) Space) in C++?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

88 Views

Here we will see one interesting problem related to array. There is an array with n elements. We have to create another array of n elements. But the i-th position of second array will hold the product of all elements of the first array except the i-th element. And one constraint is that we cannot use the division operator in this problem. We have to solve this problem in-place without using any additional spaces.If we can use the division, operation, we can easily solve this problem, by getting the product of all elements, then divide i-th element of first array ... Read More

A C/C++ Function Call Puzzle?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

176 Views

We know that C and C++ are very much similar in different aspects. The C++ has additional object oriented feature in it, but most of the C programs can also be correct in C++. Here we will see one program related to function call, that can be run when it is written in C, but will not work in C++.Example Live Demo#include void myFunction() {    printf("Function called"); } int main() {    myFunction();    myFunction(2); }OutputFunction called Function calledThis program will run in C and generates output, but when we want to compile in C++, it will return an error ... Read More

A Boolean Matrix Question in C++?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

161 Views

Here we will see one interesting Boolean matrix problem. One Boolean matrix is given which contains 0’s and 1’s. Our goal is to find where 1 is marked. If the 1 is marked at position mat[i, j], then we will make all entries to 1 of the row i and column j. Let us see an example. If the matrix is like below −1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0Then after modification, it will be −1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1AlgorithmmatrixUpdate(matrix[R, ... Read More

C/C++ program to make a simple calculator?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

809 Views

A simple calculator is a calculator that performs some basic operations like ‘+’ , ‘-’ , ‘*’ , ‘/’. A calculator does basic operation in a fast way. We will use switch statement to make a calculator.SampleOperator − ‘+’ => 34 + 324 = 358 Operator − ‘-’ => 3874 - 324 = 3550 Operator − ‘*’ => 76 * 24 = 1824 Operator − ‘/’ => 645/5 = 129Example Code#include op;    cout

A comma operator question in C/C++ ?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

200 Views

Comma Operator in C/C++ programming language has two contexts −As a Separator −As an operator − The comma operator { , } is a binary operator that discards the first expression (after evaluation) and then use the value of the second expression. This operator has the least precedence.Consider the following codes and guess the output −Example Live Demo#include int main(void) {    char ch = 'a', 'b', 'c';    printf("%c", ch);    return 0; }OutputIt gives an error because the works as a separator.prog.c: In function ‘main’: prog.c:5:20: error: expected identifier or ‘(’ before 'b' char ch = 'a', 'b', ... Read More

Power Function in C/C++

Sharon Christine
Updated on 30-Jul-2019 22:30:26

846 Views

Power function is used to calculate the power of the given number.The pow function find the value of a raised to the power b i.e. ab.Syntaxdouble pow(double a , double b)It accepts a double integers as input and output a double integer as output. It pow() function is defined in math.h package.If you pass an integer to the power function, the function converts it into double data type. But there's an issue with this, sometimes this conversion might store this as a lower double. For example, if we pass 3 and is converted as 2.99 then the square is 8.99940001 ... Read More

C++ Program to Find the Minimum value of Binary Search Tree

Smita Kapse
Updated on 30-Jul-2019 22:30:26

229 Views

It is a program to find the minimum value of a binary search tree.AlgorithmsBegin    Declare nd as a structure.    Declare d to the integer datatype.    Declare pointer lt to the structure nd type.    Declare pointer lt to the structure nd type.    Declare function new_nd() to the structure nd type.    Declare d to the integer datatype.    Pass them as a parameter.    Declare pointer nd to the structure nd type.       Initialize nd = (struct nd*) malloc(sizeof(struct nd)).    nd->d = d.    nd->lt = NULL.    nd->rt = NULL.    return(nd). ... Read More

C++ Program to Create the Prufer Code for a Tree

Anvi Jain
Updated on 30-Jul-2019 22:30:26

675 Views

Prufer code uniquely identifies a tree which is given by user as a graph representation with labels from 1 to p. This tree consist p(value is given by user) labels of node. It has sequence of p – 2 values.AlgorithmBegin    Declare i, j, ver, edg, minimum, p to the integer datatype.    Print “Enter the number of vertexes: ”.    Enter the value of ver.    Initialize edg = ver-1.    Declare EDG[edg][2], DG[ver+1] to the integer datatype.       Initialize DG[ver+1] = {0}.    Print “This tree has (value of edg) edges for (value of ver) vertexes”. ... Read More

Print prime numbers in a given range using C++ STL

Smita Kapse
Updated on 30-Jul-2019 22:30:26

463 Views

It is the program to print prime numbers in a given range.AlgorithmsBegin    Declare a user define datatype stl.    Declare a vector number to the stl datatype.    Declare variable a to the stl datatype.    Declare vector Prime_Number to the Boolean datatype.       Prime_Number[0] = false.       Prime_Number[1] = false.    Declare b to the integer datatype.       Initialize b = sqrt(a).    for (stl pr=2; pr

Advertisements