Found 33676 Articles for Programming

Unix filename pattern matching in Python

Samual Sam
Updated on 26-Jun-2020 08:57:31

2K+ Views

Here we will see how we can get the UNIX shell style pattern matching techniques using Python. There is a module called fnmatch, which is used to do the work. This module is used to compare file name against a pattern, then returns True or False according to the matches.To use it at first we need to import it the fnmatch standard library module.import fnmatchIn the Unix terminal, there are some wildcards to match the patterns. These are like below −‘*’ The asterisk is used to match everything.‘?’ Question Mark is for matching a single character.[seq] Sequences are used to ... Read More

Initialization of variable sized arrays in C

karthikeya Boyini
Updated on 26-Jun-2020 08:59:10

7K+ Views

Variable sized arrays are data structures whose length is determined at runtime rather than compile time. These arrays are useful in simplifying numerical algorithm programming. The C99 is a C programming standard that allows variable sized arrays.A program that demonstrates variable sized arrays in C is given as follows −Example Live Demo#include int main(){    int n;    printf("Enter the size of the array: ");    scanf("%d", &n);    int arr[n];    for(int i=0; i

How to print a variable name in C?

karthikeya Boyini
Updated on 26-Jun-2020 09:00:16

1K+ Views

The following is an example to print variable name.Example Live Demo#include #define VariableName(name) #name int main() {    int name;    char ch;    printf("The variable name : %s", VariableName(name));    printf("The variable name : %s", VariableName(ch));    return 0; }OutputThe variable name : name The variable name : chIn the above program, the variable names are printed by defining the method before main()#define VariableName(name) #nameTwo variables of different datatypes are declared. By using the defined function, variable names are printed.int name; char ch; printf("The variable name : %s", VariableName(name)); printf("The variable name : %s", VariableName(ch));

Write a power (pow) function using C++

Samual Sam
Updated on 26-Jun-2020 09:02:50

2K+ Views

The power function is used to find the power given two numbers that are the base and exponent. The result is the base raised to the power of the exponent.An example that demonstrates this is as follows −Base = 2 Exponent = 5 2^5 = 32 Hence, 2 raised to the power 5 is 32.A program that demonstrates the power function in C++ is given as follows −Example Live Demo#include using namespace std; int main(){    int x, y, ans = 1;    cout > x;    cout > y;    for(int i=0; i

The static keyword and its various uses in C++

karthikeya Boyini
Updated on 26-Jun-2020 09:03:47

400 Views

When static keyword is used, variable or data members or functions can not be modified again. It is allocated for the lifetime of program. Static functions can be called directly by using class name.Static variables are initialized only once. Compiler persist the variable till the end of the program. Static variable can be defined inside or outside the function. They are local to the block. The default value of static variable is zero. The static variables are alive till the execution of the program.The following is the syntax of static keyword.static datatype variable_name = value; // Static variable    static ... Read More

C++ Program to Find Fibonacci Numbers using Iteration

Tapas Kumar Ghosh
Updated on 21-Apr-2025 18:06:34

8K+ Views

The term Fibonacci numbers is used in mathematics, which calculates the sum of two preceding numbers that starts from 0 and 1 and continues till based on the given number say num. Mathemathematically, it is represented by: Fn = Fn-1 + Fn-2 Let us take an example to understand the above formula based on fibonacci numbers. F0 = 0 F1 = 1 F2 = F1 + F0 = 1 + 0 = 1 F3 = F2 + F1 = 1 + 1 = 2 F4 = F3 + F2 = 2 + 1 = 3 ... Read More

C++ Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers

Tapas Kumar Ghosh
Updated on 09-Jun-2025 11:28:29

1K+ Views

You are given a number and you need to write a C++ program to check whether a number can be expressed as sum of two prime numbers. Input / Output Scenarios Following is the input-output statement: Input: n = 19 Output: 19 can be expressed as the sum of two prime numbers. Explanation: 19 = 17 + 2, and both 17 and 2 are prime numbers. Input: n = 36 Output: 36 can be expressed as the sum of two prime numbers. Explanation: 36 = 31 + 5, and both 31 and 5 are prime numbers. C++ Program ... Read More

C++ Program to Compute Combinations using Factorials

Samual Sam
Updated on 26-Jun-2020 08:39:33

976 Views

The following is an example to compute combinations using factorials.Example Live Demo#include using namespace std; int fact(int n) {    if (n == 0 || n == 1)    return 1;    else    return n * fact(n - 1); } int main() {    int n, r, result;    coutn;    coutr;    result = fact(n) / (fact(r) * fact(n-r));    cout

C++ Program to Find Factorial of Large Numbers

Tapas Kumar Ghosh
Updated on 21-Apr-2025 18:09:05

2K+ Views

A factorial of a number defines the non-negative integer say n that calculate the product of a number by every positive integer until it reaches 1. The symbol of factorial is (!). Mathematically, it is represented by: n! = n x (n-1) x (n-2) x ... x 1 For eg. factorial of an integer 30! = 265252859812191058636308480000000. 30! = 30x29x28x27x26x25x24x23x22x21x20x19x18x17x16x15x14x13x12x11x10x9x8x7x6x5x4x3x2x1 A non-negative integer is defined by any whole number that is 0 or positive (not a fraction or decimal). What is Large Number? In context of calculating the factorial number, the large number denotes the n value ... Read More

C++ Program to Find Fibonacci Numbers using Recursion

Tapas Kumar Ghosh
Updated on 21-Apr-2025 18:49:30

71K+ Views

The Fibonacci sequence is a sequence of numbers in which each number is the sum of the two numbers that precede it. ExampleBelow is the mathematical example to understand the logic of the Fibonacci number: Suppose, n = 3, then, F(0) = 0 F(1) = 1 F(2) = F(1) + F(0) = 1 + 0 = 1 F(3) = F(2) + F(1) = 1 + 1 = 2 .... .... So, Fibonacci numbers from F(0) to F(3): 0, 1, 1, 2.In this article, we will learn how to implement a C++ program to generate a Fibonacci series using recursion. ... Read More

Advertisements