Found 26504 Articles for Server Side Programming

C++ program to implement Simpson’s 3/8 rule

Ayush Gupta
Updated on 03-Dec-2019 10:34:00

1K+ Views

In this tutorial, we will be discussing a program to implement SImpson’s ⅜ rule.Simpson’s ⅜ rule is used for doing numerical integrations. The most common use case of this method is in performing numerical approximations of definite integrals.In this, the parabolas on the graph are used for performing the approximations.Example#include using namespace std; //function that is to be integrated float func_inte( float x){    return (1 / ( 1 + x * x )); } //calculating the approximations float func_calculate(float lower_limit, float upper_limit, int interval_limit ){    float value;    float interval_size = (upper_limit - lower_limit) / interval_limit;    float ... Read More

C# Stack.TrimExcess() Method with Examples

AmitDiwan
Updated on 03-Dec-2019 10:35:34

612 Views

The Stack.TrimExcess() method in C# is used to set the capacity to the actual number of elements in the List, if that number is less than a threshold value.Syntaxpublic void TrimExcess ();Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       Stack stack = new Stack();       stack.Push(100);       stack.Push(150);       stack.Push(175);       stack.Push(200);       stack.Push(225);       stack.Push(250);       stack.Push(300);       stack.Push(400);       stack.Push(450);       stack.Push(500);       Console.WriteLine("Elements in the ... Read More

C++ Program to implement Linear Extrapolation

Ayush Gupta
Updated on 03-Dec-2019 10:31:42

908 Views

In this tutorial, we will be discussing a program to implement Linear Extrapolation.Extrapolation is defined as a process in which the required value for a certain function is beyond the lower or the upper limits of the function definition.In the case of Linear Extrapolation, the value beyond the scope is found using the tangent made on the graph of the function to determine the required value. Linear Extrapolation gives quite accurate results when applied.Example#include using namespace std; //structuring the values of x and y struct Data {    double x, y; }; //calculating the linear extrapolation double calc_extrapolate(Data d[], ... Read More

C++ program to implement Inverse Interpolation using Lagrange Formula

Ayush Gupta
Updated on 03-Dec-2019 10:28:57

432 Views

In this tutorial, we will be discussing a program to implement Inverse Interpolation using Lagrange formula.Inverse Interpolation is defined as the method of finding the value of an independent variable from the given value of dependent value lying between two tabulated set of values for an unknown function.Example#include using namespace std; //structuring the values of x and y struct Data {    double x, y; }; //calculating inverse interpolation double calc_invinter(Data d[], int n, double y){    double x = 0;    int i, j;    for (i = 0; i < n; i++) {       double ... Read More

C++ program to implement ASCII lookup table

Ayush Gupta
Updated on 03-Dec-2019 10:25:57

433 Views

In this tutorial, we will be discussing a program to implement ASCII lookup table.ASCII lookup table is a tabular representation that provides with the octal, hexadecimal, decimal and HTML values of a given character.The character for the ASCII lookup table includes alphabets, digits, separators and special symbols.Example#include #include using namespace std; //converting decimal value to octal int Octal(int decimal){    int octal = 0;    string temp = "";    while (decimal > 0) {       int remainder = decimal % 8;       temp = to_string(remainder) + temp;       decimal /= 8; ... Read More

C++ program to implement Collatz Conjecture

Ayush Gupta
Updated on 03-Dec-2019 10:23:59

441 Views

In this tutorial, we will be discussing a program to implement Collatz Conjecture.For this, we will be given with a number n and we have to find out whether it can be converted to 1 using two operations −If n is even, n is converted to n/2.If n is odd, n is converted to 3*n + 1.Example#include using namespace std; //checking if n reaches to 1 or not bool check1(int n, unordered_set &s){    if (n == 1)       return true;    if (s.find(n) != s.end())       return false;    return (n % 2)? check1(3*n + ... Read More

Array.BinarySearch(Array, Object) Method with examples in C#

AmitDiwan
Updated on 03-Dec-2019 10:27:25

176 Views

The Array.BinarySearch(Array, Object) method in C# is used to search an entire one-dimensional sorted array for a specific element, using the IComparable interface implemented by each element of the array and by the specified object.Syntaxpublic static int BinarySearch (Array arr, object val);Above, arr is the sorted 1-D array, whereas val is the object to search for.Example Live Demousing System; public class Demo {    public static void Main() {       int[] intArr = {5, 10, 15, 20};       Array.Sort(intArr);       Console.WriteLine("Array elements...");       foreach(int i in intArr) {          Console.WriteLine(i); ... Read More

C++ program to get the Sum of series: 1 – x^2/2! + x^4/4! -…. upto nth term

Ayush Gupta
Updated on 03-Dec-2019 10:20:32

1K+ Views

In this tutorial, we will be discussing a program to get the sum of series 1 – x^2/2! + x^4/4! … upto nth term.For this we will be given with the values of x and n. Our task will be to calculate the sum of the given series upto the given n terms. This can be easily done by computing the factorial and using the standard power function to calculate powers.Example#include #include //calculating the sum of series double calc_sum(double x, int n){    double sum = 1, term = 1, fct, j, y = 2, m;    int ... Read More

C# Copy() Method

AmitDiwan
Updated on 03-Dec-2019 10:19:27

490 Views

The Copy() method in C# is used to create a new instance of String with the same value as a specified String.Syntaxpublic static string Copy (string s);Above, s is the string to copy.Example Live Demousing System; public class Demo {    public static void Main(string[] args) {       string s1 = "Amy";       string s2 = "Katie";       string s3 = String.Copy(s2);       Console.WriteLine("String1 = "+s1);       Console.WriteLine("String2 = "+s2);       Console.WriteLine("Are both the strings equal? = "+s1.Equals(s2));       Console.WriteLine("Are both the strings equal? = "+s2.Equals(s3));   ... Read More

C++ program to generate random alphabets

Ayush Gupta
Updated on 03-Dec-2019 10:17:22

893 Views

In this tutorial, we will be discussing a program to generate random alphabets.For this, we will have a fixed size of array/string and use the rand() function to generate a random string of alphabets.Example#include using namespace std; const int MAX = 26; //generating a string of random alphabets string gen_random(int n){    char alphabet[MAX] = {       'a', 'b', 'c', 'd', 'e', 'f', 'g',       'h', 'i', 'j', 'k', 'l', 'm', 'n',       'o', 'p', 'q', 'r', 's', 't', 'u',       'v', 'w', 'x', 'y', 'z'    };    string res ... Read More

Advertisements