Find Largest Element in an Array in C++

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

495 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

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

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

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

Explain ValueFromPipeline in PowerShell Advanced Functions

Chirag Nagrekar
Updated on 04-May-2020 07:15:45

5K+ Views

Consider the below example, we have created Advanced function to get the specific process information like Process Name, Process ID (PID), Start Time, Responding status, etc.function Get-ProcessInformation{    [cmdletbinding()]    param(       [Parameter(Mandatory=$True)]       [string[]]$name    )    Begin{       Write-Verbose "Program started"    }    Process{       Write-Verbose "Extracting Process Inforamtion" Get-Process $name | Select Name, ID, StartTime, Responding | ft - AutoSize    }    End{       Write-Verbose "Function ends here"    } }Above is the advanced function example. When we run the above command, it will give ... Read More

AllowEmptyString and AllowEmptyCollection in PowerShell Advanced Function

Chirag Nagrekar
Updated on 04-May-2020 07:04:15

4K+ Views

AllowEmptyString() attribute works with the string variable and AllowEmptyCollection() work with the array of different data types (Collection).Consider the example below. Here, we are using a mandatory variable $name which is a string and $stringarray which is a string array.function print_String{    [cmdletbinding()]    param(       [parameter(Mandatory=$True)]       [string]$name,    )    Write-Output "Writing a single string"    $name }If we get the output of the above variable it will generate an error below.PS C:\WINDOWS\system32> print_String cmdlet print_String at command pipeline position 1 Supply values for the following parameters: name: print_String : Cannot bind argument to ... Read More

Mandatory Attribute in PowerShell Advanced Function

Chirag Nagrekar
Updated on 04-May-2020 07:01:04

457 Views

We have an example of PowerShell advanced function below and we will try to understand how mandatory parameter works.function math_Operation{    [cmdletbinding()]    param([int]$val1, [int]$val2)    Write-Host "Multiply : $($val1*$val2)"    Write-Host "Addition : $($val1+$val2)"    Write-Host "Subtraction : $($val1-$val2)"    Write-Host "Divide : $($val1+$val2)" }When you execute the above example and don’t supply values then the script won’t ask you for the values, by default it will take the values and execute the program. See the execution below.PS C:\WINDOWS\system32> math_Operation Multiply : 0 Addition : 0 Subtraction : 0 Divide : 0Even if you have mentioned two variables ($val1, ... Read More

Explain the PowerShell Advanced Function

Chirag Nagrekar
Updated on 04-May-2020 06:56:58

733 Views

Before starting the Advance PowerShell function, assuming we know about the PowerShell function. You can check the explanation on the PowerShell function below.https://www.tutorialspoint.com/explain-the-powershell-functionHere, we will take the math function example that calculates the different types of operations. We already have a code with the simple function as shown below.function math_Operation{    param([int]$val1, [int]$val2)    Write-Host "Multiply : $($val1*$val2)"    Write-Host "Addition : $($val1+$val2)"    Write-Host "Subtraction : $($val1-$val2)"    Write-Host "Divide : $($val1+$val2)" }The above example is of the simple function. When you run the above code and run the function from the terminal and you can notice you will ... Read More

Insertion Sort List in C++

Arnab Chakraborty
Updated on 04-May-2020 06:42:29

302 Views

Suppose we have a linked list, we have to perform the insertion sort on this list. So if the list is like [9, 45, 23, 71, 80, 55], sorted list is [9, 23, 45, 55, 71, 80].To solve this, we will follow these steps −dummy := new Node with some random valuenode := given listwhile node is not null, newNode = next of node, dummyHead := next of dummy, prevDummyHead := dummywhile true −if dummyHead is not present, value of dummyHead > value of nodenext of node := dummyHeadnext of prevDummyHead := nodebreak the loopprevDummyHead := dymmyHead, and dummyHead = ... Read More

Binary Tree Preorder Traversal in Python

Arnab Chakraborty
Updated on 04-May-2020 06:38:33

1K+ Views

Suppose we have a binary tree. We have to return the preorder traversal of that tree. So if the tree is like −Then the preorder traversal will be: [3, 9, 20, 15, 7]To solve this, we will follow these steps −make empty lists called res and st.node := rootwhile node or st is not emptywhile node is not null, theninsert val of node into res, insert node into st and set node := left of nodetemp := last element of st, and delete last element of stif right of temp is available, thennode := right of tempreturn resLet us see ... Read More

Advertisements