- 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 1401 Articles for C
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
475 Views
Modified game of Nim is an optimisation games of arrays. This game predicts the winner based on the starting player and optimal moves.Game Logic − In this game, we are given an array{}, that contains elements. There are generally two players that play the game namly player1 and player2. The aim of both is to make sure that all their numbers are removed from the array. Now, player1 has to remove all the numbers that are divisible by 3 and the player2 has to remove all the numbers that are divisible by 5. The aim is to make sure that ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
234 Views
A binary tree is a tree data structure in which there are two child nodes for each node. The child nodes being two are referred as, left and right child.A BST is a tree structure in which left subtree contains nodes with values lesser than root and right subtree contains nodes with values greater that root.Here, we will check if a binary tree is a BST or not −To check for this we have to check for the BST condition on the binary tree. For a root node check for left child should be less that root, right child should ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
22K+ Views
A knapsack is a bag. And the knapsack problem deals with the putting items to the bag based on the value of the items. It aim is to maximise the value inside the bag. In 0-1 Knapsack you can either put the item or discard it, there is no concept of putting some part of item in the knapsack.Sample ProblemValue of items = {20, 25, 40} Weights of items = {25, 20, 30} Capacity of the bag = 50Weight distribution25, 20{1, 2} 20, 30 {2, 3} If we use {1, 3} the weight will be above the max allowed value. ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
69 Views
The bitonicity of an array is defined using the following syntax −To find bitonicity of an array based on its elements is −Bitonicity = 0 , initially arr[0] i from 0 to n Bitonicity = Bitonicity+1 ; if arr[i] > arr[i-1] Bitonicity = Bitonicity-1 ; if arr[i] < arr[i-1] Bitonicity = Bitonicity ; if arr[i] = arr[i-1]ExampleThe code for finding the bitonicity of an array we have used a variable called bitonicity, that changes its based on the comparison of the current and previous elements of the array. The above logic updates the bitonicity of the array and final bitonicity ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
102 Views
A tetrahedron is a pyramid with triangular base i.e. it has a base that is a triangle and each side has a triangle. All the three triangles converge to a point. As in the figure, Area of Tetrahedron = (√3)a2ExampleThe code to find the area of tetrahedron uses the math library to find the square and square-root of a number using sqrt and pow methods. For calculating the area we take a floating point and the value of the expression "((sqrt(3)*a*a))" is given to it.#include #include int main() { int a= 5; float area, volume; ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
616 Views
DFA stands for Deterministic Finite Automata. It is a finite state machine that accepts or a string based on its acceptor.Here, we are going to make a DFA that accepts a string that starts and ends with a. The input is from the set (a, b). Based on this we will design a DFA. Now, Let's discuss some valid and invalid cases that are accepted by a DFA.Strings that are accepted by DFA: ababba, aabba, aa, a.Strings that are not accepted by DFA: ab, b, aabab.ExampleThis program check for a string that starts and ends with a. This DFA will ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
157 Views
Here we will see one problem. We have one binary array. It has n elements. Each element will be either 0 or 1. Initially, all elements are 0. Now we will provide M commands. Each command will contain start and end indices. So command(a, b) is indicating that the command will be applied from element at position a to element at position b. The command will toggle the values. So it will toggle from ath index to bth index. This problem is simple. check the algorithm to get the concept.AlgorithmtoggleCommand(arr, a, b)Begin for each element e from index a ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
179 Views
Here we will see the area of the biggest square that can be inscribed in an equilateral triangle. The side of the triangle is ‘a’ and the side of the square is x.The side of the triangle ‘a’ is −So x is −Example#include #include using namespace std; float areaSquare(float a) { //a is side of triangle if (a < 0 ) //if a is negative, then this is invalid return -1; float area = a / (1 + 2/sqrt(3)); return area; } int main() { float a = 7; cout
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
62 Views
Here we will see the area of biggest Reuleaux triangle inscribed within a square. The side of the square is ‘a’. And the height of the Reuleaux triangle is h.The height of the Reuleaux triangle is same as a. So a = h. So the area of Reuleaux triangle is −Example#include #include using namespace std; float areaReuleaux(float a) { //side of square is a if (a < 0) //if a is negative it is invalid return -1; float area = ((3.1415 - sqrt(3)) * (a) * (a))/2; return area; } int main() { float side = 8; cout
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
66 Views
Here we will see the area of biggest Reuleaux triangle inscribed within a square, That square is inscribed inside one circle. The side of the square is ‘a’. The radius of the circle is ‘r’. As we know that the diagonal of the square is the diameter of the circle. So −2𝑟 = 𝑎√2 𝑎 = 𝑟√2And the height of the Reuleaux triangle is h.The height of the Reuleaux triangle is same as a. So a = h. So the area of Reuleaux triangle is −Example#include #include using namespace std; float areaReuleaux(float r) { //radius of ciecle is ... Read More