Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
C Articles
Page 43 of 96
What are the differences between bitwise and logical AND operators in C/C++
In C, the bitwise AND (&) and logical AND (&&) operators serve different purposes and work with different data types. Understanding their differences is crucial for correct C programming. Syntax // Bitwise AND result = operand1 & operand2; // Logical AND result = condition1 && condition2; Bitwise AND Operator (&) The bitwise AND (&) operator performs a bit-by-bit AND operation between two integers. It works on integer types and returns the same data type. Each corresponding bit is AND-ed according to these rules − 1 & 1 = 1 ...
Read MoreC Program Coin Change
In this problem, we are given a value n, and we want to make change of n rupees using a given set of coin denominations. We need to return the total number of ways to make the sum using these coins. Syntax int coinChange(int coins[], int numCoins, int amount); Example Input/Output Input: N = 6, coins = {1, 2, 4} Output: 6 Explanation: The total combinations that make the sum of 6 are: {1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 2}, {1, 1, 2, 2}, {1, 1, 4}, {2, 2, ...
Read MoreC / C++ Program for Dijkstra\'s shortest path algorithm
Dijkstra's algorithm is a greedy algorithm used to find the shortest path from a source vertex to all other vertices in a weighted graph. It works by maintaining a set of vertices whose shortest distance from the source has been determined and gradually expanding this set until all vertices are included. Syntax void dijkstra(int graph[V][V], int source); Algorithm Steps Step 1: Create a set to store vertices included in shortest path tree Step 2: Initialize all distances as INFINITE and source distance as 0 Step 3: Loop until all vertices are processed: ...
Read MoreBinary to Gray code using recursion in C program
A Binary number is a number that has only two bits 0 and 1. Gray code is a special type of binary number that has a property that two successive numbers of the code cannot differ by more than one bit. This property of gray code makes it useful in K-maps, error correction, communication, etc. This makes the conversion of binary to gray code necessary. So, let's see an algorithm to convert binary to gray code using recursion. Syntax int binaryToGray(int binary); Algorithm Step 1: For input n: Step ...
Read MoreBinary Search for Rational Numbers without using floating point arithmetic in C program
In this problem, we are given a sorted array of rational numbers and we have to search the given element using binary search algorithm without using floating point arithmetic. A Rational number is a number represented in the form p/q where both p and q are integers. For example, 2/3, 1/5. Binary search is a searching technique that works by finding the middle of the array and comparing elements to determine which half contains the target. For finding the element using binary search from a sorted array of rational numbers, where floating point arithmetic is not allowed, ...
Read MoreC program to delete a file
In programming, working with files is very important and every programming language has its own set of functions or library that help in manipulation of files. In C Programming Language, the remove() function can be used by the programmer to delete a file. Syntax int remove(const char *filename); Parameters The function accepts one parameter which is the name of the file that is to be deleted. File name can also be the path to the file but only if the system supports it. filename − A string containing the name of the ...
Read MoreC program to find the Roots of Quadratic equation
In this tutorial, we will be discussing a program to find the roots of a quadratic equation using the quadratic formula. Given a quadratic equation of the form ax2 + bx + c = 0, our task is to find the roots x1 and x2 of the given equation. For this, we use the discriminant method where the discriminant D = b2 - 4ac determines the nature of the roots. Syntax D = b*b - 4*a*c x1 = (-b + sqrt(D)) / (2*a) x2 = (-b - sqrt(D)) / (2*a) Nature of Roots ...
Read MoreC Program for Hexagonal Pattern
We are given with an integer 'n' and the task is to generate the hexagonal pattern and display the final output. Syntax void pattern(int n); Example Let's see the hexagonal pattern for n=5 and n=4 − Input: n=5 Output: * * * * * * * * * * * * * * ...
Read MoreC Program for Circumference of a Parallelogram
We are given the sides of a parallelogram and the task is to calculate the circumference of the parallelogram with its given sides and display the result. What is a Parallelogram? A parallelogram is a type of quadrilateral which has − Opposite sides parallel and equal Opposite angles equal Diagonals bisect each other In the below figure, 'a' and 'b' are the sides of a parallelogram where parallel sides are shown. a a b b ...
Read MoreC program for Binomial Coefficients table
Given with a positive integer value let's say 'val' and the task is to print the value of binomial coefficient B(n, k) where, n and k be any value between 0 to val and hence display the result. What is Binomial Coefficient Binomial coefficient (n, k) is the order of choosing 'k' results from the given 'n' possibilities. The value of binomial coefficient of positive n and k is given by − Syntax C(n, k) = n! / (k! * (n-k)!) where, n >= k Example of Binomial Coefficient Calculation For ...
Read More