- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7347 Articles for C++
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
A number whose sum of its digits powered with its respective position equals to the number itself is called a disarium number.The noOfDigits(int num) function takes the number and return the number of digits by constantly dividing the number by 10 while there is only ones place left. On each iteration the digits variable is incremented to keep the digits track and is returned once the while loop ends.int noOfDigits(int num){ int digits = 0; int temp = num; while (temp){ temp= temp/10; digits++; } return digits; }Next, isDisarium(int ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
80 Views
Let us first define the struct that would represent a tree node that contains the int key and its left and right node child. If this is the first node to be created then it’s a root node otherwise a child node.struct Node { int data; struct Node *leftChild, *rightChild; };Next we create our createNode(int key) function that takes an int key value and assign it to the key member of the node. The function returns the pointer to the created struct Node. Also, the left and right child of the newly created node are set to null.Node* ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
196 Views
Let us first define the struct that would represent a tree node that contains a character key and a vector of Node *.struct Node{ char key; vector children; };Next we create our createNode(int key) function that takes an int key value and assign it to the key member of the node. The function returns the pointer to the created struct node.Node *createNode(int key){ Node *node = new Node; node->key = key; return node; }Our depthOfTree(struct Node* root) function takes the root node as parameter. If the root is NULL then the depth is returned as ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
103 Views
The density of a binary tree is calculated by dividing its size by its height.Binary tree density = size/height.Let us first define the struct that would represent a tree node that contains the data and its left and right node child. If this is the first node to be created then it’s a root node otherwise a child node.struct Node { int data; struct Node *leftChild, *rightChild; };Next we create our createNode(int data) function that takes an int value and assign it to the data member of the node. The function returns the pointer to the created struct ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
204 Views
The deletion is to be performed by replacing the deleted mode by bottom and rightmost node.Let us first define the struct that would represent a tree node that contains the data and its left and right node child. If this is the first node to be created then it’s a root node otherwise a child node.struct Node { int data; struct Node *leftChild, *rightChild; };Next we create our newNode(int data) function that takes an int value and assign it to the data member of the node. The function returns the pointer to the created struct Node. Also, the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
105 Views
To find the length of the diagonal we put the value of side in 2*side*sin (900/14). The value of sin (900/14) = 0.9.ExampleLet us see the following implementation to get the regular Heptagon diagonal from its side − Live Demo#include using namespace std; int main(){ float side = 12; if (side < 0) return -1; float diagonal = 2*side*0.9; cout
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
156 Views
Demlo numbers are palindromic numbers that are generated by the square of number of form 11..1 given that the number is less than 10 digits.Let us first declare the string variables −string demNum = "1111"; string square = "";Now, we loop till the length of the demNum string. Inside the loop we convert the index value i to string and append it to square variable.for(int i=1 ;i= 1; i--) square += char(i + '0');ExampleLet us see the following implementation to get a better understanding of demlo numbers − Live Demo#include using namespace std; int main(){ string demNum = ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
135 Views
Let us first define our binary tree using a class containing int data, btree_node * rightChild, btree_node * leftChild. The leftChild and rightChild are pointers to btree_node. All the members in our class are public.class btree_node { public: int data; btree_node* leftChild; btree_node* rightChild;For creating a new node we have the constructor function that takes the int value as parameter to assign it to the newly created node value. The leftChild and rightChild are set to null.btree_node(int data){ this->data = data; this->leftChild = NULL; this-> = NULL; ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
151 Views
Let us first define our linked list that contains data and the pointer to the next node.struct Node { int data; struct Node* next; };We then create our createList(Node ** headPtr, int new_data) function which takes a doublePointer to the Node and an int value. Inside the function we assign the newly created node next pointer to the headptr and then the headptr to the newly created node.void createList(Node ** headPtr, int new_data){ Node* newNode = new Node(); newNode->data = new_data; newNode->next = (*headPtr); (*headPtr) = newNode; }The deleteNnodesAfterM(Node *head, int M, int N) ... Read More