找到 34423 篇文章,关于编程

C# Stack.TrimExcess() 方法及示例

AmitDiwan
更新于 2019-12-03 10:35:34

526 次查看

C# 中的 Stack.TrimExcess() 方法用于将容量设置为列表中元素的实际数量(如果该数量小于阈值)。语法public void TrimExcess ();示例 在线演示using 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("元素在… 阅读更多

C++ 程序实现线性外推

Ayush Gupta
更新于 2019-12-03 10:31:42

721 次查看

在本教程中,我们将讨论一个实现线性外推的程序。外推被定义为一个过程,其中某个函数的所需值超出了函数定义的下限或上限。在线性外推的情况下,使用在函数图上绘制的切线来找到超出范围的值,以确定所需的值。线性外推在应用时能给出相当准确的结果。示例#include using namespace std; //构造 x 和 y 的值 struct Data {    double x, y; }; //计算线性外推 double calc_extrapolate(Data d[], ... 阅读更多

C++ 程序使用拉格朗日公式实现逆插值

Ayush Gupta
更新于 2019-12-03 10:28:57

369 次查看

在本教程中,我们将讨论一个使用拉格朗日公式实现逆插值的程序。逆插值被定义为从给定依赖变量的值(位于未知函数的两个表格化值集之间)中找到自变量值的方法。示例#include using namespace std; //构造 x 和 y 的值 struct Data {    double x, y; }; //计算逆插值 double calc_invinter(Data d[], int n, double y){    double x = 0;    int i, j;    for (i = 0; i < n; i++) {       double ... 阅读更多

C# 中的 Array.LastIndexOf() 方法

AmitDiwan
更新于 2019-12-03 10:30:28

2K+ 次查看

C# 中的 Array.LastIndexOf() 方法用于搜索指定的对象,并返回该对象在整个一维数组中最后一次出现的索引。语法public static int LastIndexOf (Array arr, object val);其中,arr 是要搜索的一维数组,而 val 是要在 arr 中定位的对象。示例 在线演示using System; public class Demo {    public static void Main() {       string[] strArr = {"John", "Tim", "Fedric", "Gary", "Harry", "Damien", "David", "Harry"};       Array.Sort(strArr);       Console.WriteLine("数组元素...");       foreach(string s in strArr) {          Console.WriteLine(s);       ... 阅读更多

C++ 程序实现 ASCII 查找表

Ayush Gupta
更新于 2019-12-03 10:25:57

374 次查看

在本教程中,我们将讨论一个实现 ASCII 查找表的程序。ASCII 查找表是一个表格表示,它提供了给定字符的八进制、十六进制、十进制和 HTML 值。ASCII 查找表的字符包括字母、数字、分隔符和特殊符号。示例#include #include using namespace std; //将十进制值转换为八进制 int Octal(int decimal){    int octal = 0;    string temp = "";    while (decimal > 0) {       int remainder = decimal % 8;       temp = to_string(remainder) + temp;       decimal /= 8; ... 阅读更多

C++ 程序实现考拉兹猜想

Ayush Gupta
更新于 2019-12-03 10:23:59

374 次查看

在本教程中,我们将讨论一个实现考拉兹猜想的程序。为此,我们将得到一个数字 n,我们必须找出它是否可以使用以下两个操作转换为 1:如果 n 是偶数,则 n 转换为 n/2。如果 n 是奇数,则 n 转换为 3*n + 1。示例#include using namespace std; //检查 n 是否达到 1 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 + ... 阅读更多

C# 中的 Array.BinarySearch(Array, Object) 方法及示例

AmitDiwan
更新于 2019-12-03 10:27:25

133 次查看

C# 中的 Array.BinarySearch(Array, Object) 方法用于使用每个数组元素和指定对象实现的 IComparable 接口搜索整个一维排序数组中的特定元素。语法public static int BinarySearch (Array arr, object val);其中,arr 是排序的一维数组,而 val 是要搜索的对象。示例 在线演示using System; public class Demo {    public static void Main() {       int[] intArr = {5, 10, 15, 20};       Array.Sort(intArr);       Console.WriteLine("数组元素...");       foreach(int i in intArr) {          Console.WriteLine(i); ... 阅读更多

C++ 程序计算级数和:1 – x^2/2! + x^4/4! -…. 直到第 n 项

Ayush Gupta
更新于 2019-12-03 10:20:32

889 次查看

在本教程中,我们将讨论一个计算级数 1 – x^2/2! + x^4/4! … 直到第 n 项的和的程序。为此,我们将得到 x 和 n 的值。我们的任务将是计算给定级数直到给定 n 项的和。这可以通过计算阶乘和使用标准幂函数来计算幂来轻松完成。示例#include #include //计算级数和 double calc_sum(double x, int n){    double sum = 1, term = 1, fct, j, y = 2, m;    int ... 阅读更多

C# Copy() 方法

AmitDiwan
更新于 2019-12-03 10:19:27

422 次查看

C# 中的 Copy() 方法用于创建一个新字符串实例,其值与指定的字符串相同。语法public static string Copy (string s);其中,s 是要复制的字符串。示例 在线演示using 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("这两个字符串是否相等?= "+s1.Equals(s2));       Console.WriteLine("这两个字符串是否相等?= "+s2.Equals(s3));   ... 阅读更多

C++ 程序生成随机字母

Ayush Gupta
更新于 2019-12-03 10:17:22

673 次查看

在本教程中,我们将讨论一个生成随机字母的程序。为此,我们将有一个固定大小的数组/字符串,并使用 rand() 函数生成一个随机的字母字符串。示例#include using namespace std; const int MAX = 26; //生成一个随机字母字符串 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 ... 阅读更多

广告

© . All rights reserved.