Programming Articles - Page 1969 of 3366

Program to find last two digits of Nth Fibonacci number in C++

Ayush Gupta
Updated on 09-Oct-2020 07:22:00

623 Views

In this problem, we are given a number N. Our task is to create a Program to find last two digits of Nth Fibonacci number in C++.Problem DescriptionWe need to find the last two digits (i.e. the two LSB’s ) of the Nth Fibonacci number. Let’s take an example to understand the problem, Input: N = 120 Output: 81Solution ApproachA simple solution will be using the direct Fibonacci formula to find the Nth term. But this method will not be feasible when N is a large number. So to overcome this, we will use the property of the Fibonacci Series that ... Read More

Program to find LCM of two Fibonnaci Numbers in C++

Ayush Gupta
Updated on 09-Oct-2020 07:34:02

210 Views

In this problem, we are given two numbers N and M. Our task is to create a program to find LCM of two Fibonacci Numbers in C++.Problem Description − We will find the Nth and Mth Fibonacci number. And then we will find the LCM of their two numbers and return the result.Fibonacci Numbers0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377....Let’s take an example to understand the problem,  Input: N = 4, B = 9Output:Explanation4th Fibonacci number is 29th Fibonacci number is 21LCM is 42.Solution ApproachTo solve the problem, we need to find ... Read More

Program to find last two digits of 2^n in C++

Ayush Gupta
Updated on 09-Oct-2020 07:40:41

633 Views

In this problem, we are given a number N. Our task is to create a Program to find last two digits of 2^n in C++.Problem DescriptionTo find the last two digits. We will use only the product of the last two digits. And leave other things to make the calculation small.Let’s take an example to understand the problem, Input: N = 12 Output: 96Explanation2^12 = 4096Solution ApproachTo solve the problem, a direct approach could be finding the value of 2^N and then finding the remainder when it is divided by 100.Example Live Demo#include using namespace std; int findLastDigit(int N){    int ... Read More

Program to find last digit of n’th Fibonnaci Number in C++

Ayush Gupta
Updated on 09-Oct-2020 08:47:13

585 Views

In this problem, we are given a number N. Our task is to create a Program to find last digit of Nth Fibonacci number in C++.Problem DescriptionWe need to find the last digit (i.e. LSB ) of the Nth Fibonacci number.Let’s take an example to understand the problem, Input: N = 120 Output: 1Solution ApproachA simple solution will be using the direct Fibonacci formula to find the Nth term. But this method will not be feasible when N is a large number. So to overcome this thing, we will use the property of the Fibonacci Series that the last digit ... Read More

Program to find largest element in an array in C++

Ayush Gupta
Updated on 04-May-2020 07:39:16

494 Views

In this tutorial, we will be discussing a program to find the largest element in an array.For this, we will be provided with an array. Our task is to find the largest number from the elements inside the array.Example Live Demo#include using namespace std; //finding largest integer int largest(int arr[], int n){    int i;    int max = arr[0];    //traversing other elements    for (i = 1; i < n; i++)    if (arr[i] > max)       max = arr[i];    return max; } int main(){    int arr[] = {10, 324, 45, 90, 9808};    int n = sizeof(arr) / sizeof(arr[0]);    cout

Program to find if a character is vowel or Consonant in C++

Ayush Gupta
Updated on 04-May-2020 07:35:56

256 Views

In this tutorial, we will be discussing a program to find if a character is a vowel or consonant.For this, we will be provided with a character. Our task is to print out to the user whether the provided character is a vowel or a consonant.Example Live Demo#include using namespace std; //checking if the character is a vowel or consonant void is_vowel(char x){    if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u')       cout

Program to find HCF iteratively in C++

Ayush Gupta
Updated on 04-May-2020 07:21:14

255 Views

In this tutorial, we will be discussing a program to find HCF iteratively.For this, we will be provided with two numbers. Our task is to calculate the HCF of the given numbers using an iterative function.Example Live Demo#include using namespace std; int get_HCF(int a, int b){    while (a != b){       if (a > b)          a = a - b;       else          b = b - a;    }    return a; } int main(){    int a = 60, b = 96;    cout

Program to find N-th term of series 3, 5, 33, 35, 53… in C++

Ayush Gupta
Updated on 04-May-2020 07:19:07

161 Views

In this tutorial, we will be discussing a program to find N-th term of series 3, 5, 33, 35, 53…For this, we will be provided with a number. Our task is to find the term for the given series at that particular position.Example Live Demo#include using namespace std; //finding the nth term in the series int printNthElement(int n){    int arr[n + 1];    arr[1] = 3;    arr[2] = 5;    for (int i = 3; i

How to print pid, info, children, and destroy processes in JShell in Java 9?

raja
Updated on 03-May-2020 09:53:31

164 Views

JShell is a Java Shell tool used to execute simple java statements like classes, methods, interfaces, enums,  and etc.. evaluates it, and prints the result in a command-line prompt.Java has improved Process API to manage and control operating system processes. ProcessHandle interface identifies and provides control of native processes, methods to check processes liveness, and destroy the process. ProcessHandle.Info interface gives an Information snapshot of a process.In the below code snippet, we can print pid, info, children,  and destroy processes of Process API.in JShell tool.Snippetjshell> ProcessHandle currentProcess = ProcessHandle.current(); currentProcess ==> 3960 jshell> System.out.println("Current Process Id: = " + currentProcess.pid()); Current Process Id: = 3960 jshell> ... Read More

Random Pick with Weight in C++

Arnab Chakraborty
Updated on 02-May-2020 13:41:58

1K+ Views

Suppose we have an array w of positive integers, were w[i] describes the weight of index i, we have to define a function pickIndex() which randomly picks an index in proportion to its weight.So if the input is like [1, 3], call pickIndex() five times, then the answer may come as − 0, 1, 1, 1, 0.To solve this, we will follow these steps −Define an array v, Through the initializer, initialize asn := w[0]for i in range 1 to size of ww[i] := w[i] + w[i – 1]n := w[i]v = wThe pickIndex() will work as follows −Take a ... Read More

Advertisements