Category: C

Generate numbers from 1 to 7 with equal probability using specified function

Write an algorithm to generate numbers from 1 to 7 with equal probability using a specified function which produces random numbers between 1 to 5 with equal probability.

Implement Ternary Operator Without Using Conditional Expressions

In this post, we will see how to implement ternary-like operator in C without using conditional expressions like ternary operator, ifâ€“else expression or switch-case statements.

Determine if two integers are equal without using comparison and arithmetic operators

In this post, we will discuss how to determine if two integers are equal without using comparison operators (==, !=, < , >, < =, >=) & arithmetic operators (+, -, *, /, %).

Generate Desired Random Numbers With Equal Probability

Write an algorithm to generate random numbers from 1 to 12 with equal probability using a given function which generates random numbers from 1 to 6 with equal probability.

Return 0, 1 and 2 with equal probability using the specified function

Write an algorithm to generate 0, 1 and 2 with equal probability using a specified function which either produces 0 or 1 with 50% probability each.

Initialize all elements of an array to same value in C/C++

In the previous post, we have discussed how to how to declare and initialize arrays in C/C++. In this post, we will discuss how to initialize all elements of an array with the same value in C/C++.

Declare and initialize arrays in C/C++

In this post, we will discuss how to declare and initialize arrays in C/C++.

Get 0 and 1 with equal Probability using specified function

Write an algorithm to get 0 and 1 with equal probability using a function which generates random numbers from 1 to 5 with equal probability.

Implementation of KMP Algorithm in C, C++ and Java

In this post, we will implement KMP Algorithm in C, C++ and Java programming language.

How to return multiple values from a function in C

In this post, we will see how to return multiple values from a function in C.

Implement substr function in C

Write an efficient function to implement substr function in C. substr() function returns the substring of given string between two given indices.

Implement strstr() function in C (Iterative & Recursive)

Write an efficient program to implement strstr function in C. strstr() function returns a pointer to the first occurrence of a string in another string.