Clearing Input Buffer in C/C++

Arjun Thakur
Updated on 28-Apr-2025 15:13:54

25K+ Views

In C/C++, an input buffer is a temporary storage area where the program processes the input. Suppose, you are an user and you type some characters using a keyboard but those characters are not passed to the program directly because it involves several layers of handling such as keyboard firmware, OS input queues, and event processing. So, they first proceed with the collection of an input buffer. Next, when the program is ready, it reads from the buffer. How Input Buffer Affects a Program? The input buffer affected to the program when we are using the functions like scanf() or ... Read More

Best Practices to Organize Python Modules

Rajendra Dharmkar
Updated on 28-Apr-2025 12:30:19

512 Views

Organizing Python modules efficiently is important to maintain scalability and collaboration. Following best practices can make your project easier to understand and use. In this article, we will discuss about an structure approach to organize Python modules with a sample project and some of the best practices to organize. Sample Project Structure Samplemod is an example of a well-structured project that focuses on creating sample module. Below is the directory structure of this project - README.rst LICENSE setup.py requirements.txt sample/__init__.py sample/core.py sample/helpers.py docs/conf.py docs/index.rst tests/test_basic.py tests/test_advanced.py Let's look at these one by one - ... Read More

Overload Unary Minus Operator in C++

Nikitha N
Updated on 25-Apr-2025 17:11:15

8K+ Views

Unary operators are operators that operate only on a single operand (unlike binary operators, which operate on two operands). There are mainly thirteen unary operators that exist in C++, for example, ++, !, ~, typeof, delete, etc. Overloading Unary Minus OperatorOverloading a unary operator means defining a custom behavior for the unary operators while applying it to objects of a class. which means you can define how an operator will work when applied to instances of a class instead of using its default behavior. This operator is normally used on the left side of the object, as in +obj, !obj, ... Read More

Implement Extended Euclidean Algorithm in C++

Krantik Chavan
Updated on 25-Apr-2025 15:31:16

2K+ Views

The extended Euclidean algorithms find the greatest common divisor(GCD) of two numbers in the form of ax + by = gcd(a, b). This expression is also known as Bezout's Identity. The extended Euclidean algorithm is an extension of the Euclid algorithm that is also used to find the GCD of two numbers using repetitive division. In this article, we have two numbers and our task is to implement the extended Euclidean algorithm to find the GCD of these two numbers in C++. Steps To Implement Extended Euclidean Algorithm The steps to implement an extended Euclidean algorithm are as follows: ... Read More

How Regular Expression Alternatives Work in Python

Nikitasha Shrivastava
Updated on 25-Apr-2025 14:39:33

1K+ Views

Regular expressions are a very crucial part of Python's built-in 're' module. It is used to work with text data. One of the advantages of regex is the ability to use alternatives, which allows you to match one pattern out of multiple options. Alternatives in the regular expressions function are just like "or" statements. They help you to define many patterns to match against a given string. The vertical bar | denotes the "or" operator in regex. For example, the regex pattern PHP|Python will match either "PHP" or "Python" in a given string. The following are the 4 different ways ... Read More

Find Fibonacci Numbers Using Matrix Exponentiation in C++

Nancy Den
Updated on 25-Apr-2025 14:17:38

3K+ Views

The Fibonacci numbers, commonly denoted as F(n) forms a sequence, called the Fibonacci sequence. In Fibonacci series, each number is the sum of the two previous two numbers, starting from 0 and 1. It is represented as F(n) = F(n-1) + F(n-2). The matrix exponentiation method is used to calculate the powers of matrix efficiently with better time complexity. In this article, we provide a value of n. This n is the value up to which we want to find the Fibonacci numbers using the matrix exponentiation method in C++. Here is an example of the Fibonacci series up to ... Read More

Implement Kadane's Algorithm in C

C
Akansha Kumari
Updated on 25-Apr-2025 14:13:32

132 Views

We are given an array of integers, and we need to find the maximum sum of a contiguous subarray using Kadane’s Algorithm. Kadane’s Algorithm is an efficient way to find the maximum subarray sum in O(n) time complexity. For example, in the array {-2, 1, -3, 4, -1, 2, 1, -5, 4}, the subarray [4, -1, 2, 1] has the maximum sum 6. In this article, we are going to implement Kadane's algorithm using C. What Is Kadane's Algorithm? Kadane's algorithm is a popular and optimal algorithm used to find the maximum sum of a contiguous subarray in a given ... Read More

C++ Program to Perform Fermat Primality Test

Ravi Ranjan
Updated on 25-Apr-2025 11:22:19

870 Views

Fermat's Little theorem states that if 'p' is a prime number and 'a' is an integer that is not divisible by p, then a^(p-1) ≡ 1 modulo p or a^(p-1) mod p = 1. We will use Fermat's Little theorem to test whether the given number is a prime number or not. In this article, we have a number num and a given number of iterations itr. Our task is to implement a primality test for the given number using Fermat's theorem in C++. Steps to Perform Fermat Primality Test The steps to perform Fermat's Primality test are as ... Read More

Declarations in Python Class vs. init Method

Akshitha Mote
Updated on 24-Apr-2025 19:11:45

163 Views

In Python, the declarations within a class are not equivalent to those within the __init__() method. Let's discuss the class and __init__() method. A class is a collection of objects. It contains the blueprints or the prototype from which the objects are being created. It is a logical entity that contains some attributes and methods.  Python '__init__()' The Python __init__() function is one of the OOP's concepts. The __init__() is called automatically whenever the object is been created to a class. The __init__() function is also known as a constructor. Constructors are used to initialize ... Read More

Class Variables in Multi-Inheritance Python Classes

Mote Akshitha
Updated on 24-Apr-2025 19:10:34

435 Views

In Python, when a class is derived from more than one super-class or base class, it is known as multiple inheritance. Following is the syntax of multiple inheritance in Python - class Super1: pass class Super2: pass class MultiDerived(Super1, Super2): pass Example ofMultiple Inheritance Let's understand multiple inheritance with the following example. Here, we have created two superclasses or base classes, i.e., Superclass1 and Superclass2, and the derived class is the child class. We then create an object Obj_1 of the child class to call its methods as ... Read More

1 2 3 4 5 ... 7836 Next
Advertisements