所以我在c#中制作了一个非常简单的单词生成器程序,效果相对较好.它根据用户定义的长度生成一个单词.
该算法为序列中的每个连续字母添加辅音然后是元音,这不是理想的,但对于基本单词效果很好.
我唯一的问题是,我告诉它在字母序列中添加一个"u"如果"q"出现在它之前,但无论我做了什么,它都会使这个词至少有一个字母太长.
我在上面的评论中用星号标记了我的问题区域.这是代码:
public void WordFinder()
{
string word = null;
int cons;
int vow;
//counter
int i = 0;
bool isword = false;
Random rnd = new Random();
//set a new string array of consonants
string[] consonant = new string[]{"b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","y","z"};
//set a new string array of vowels
string[] vowel = new string[]{"a","e","i","o","u"};
while (isword == false)
{
word = null;
Console.WriteLine("Pick the length of a word");
int num = Convert.ToInt32(Console.ReadLine());
//set the counter "i" to 1
i = …Run Code Online (Sandbox Code Playgroud) 我已经放弃了数字生成器,因为我知道它实际上是将每个数字分开,直到它收到一个素数.我已经改变了代码,以便从指定的范围内素数"a" to "?" (in this case, 10)的Prime_2方法进行检查,以在总理素的方法.然后,如果该数字是素数,则通过将布尔变量prime设置为true或false来返回Prime方法,但到目前为止,我只得到2为真,其余为假.这显然不是真的.因此,我感谢任何协助/意见/建议,使这个新计划可行.
public bool Prime(long num) // Prime method with a parameter for one number
{
int div = 3; // what we divide by after checking if the number is divisible by 2
bool prime = true; // set prime to true
{
for (long i = 0; i < 100 && prime == true; i++) // run 100 passes
{
if (num % 2 == 0 && num != …Run Code Online (Sandbox Code Playgroud) 我编写了一系列矩阵运算,其中我使用二维浮点数组,将其视为矩阵,然后对其进行矩阵运算以获得逆。我的问题是,尽管我与类方法一起使用的数组不是类的一部分,但是每次我以数组为参数运行该方法时,数组本身也会被修改。
首先,我将描述如何得到矩阵的逆,然后将显示输出。
求矩阵逆的步骤如下:
现在,我将在实现这些操作的地方展示代码。为了简洁起见,我不会描述如何获取未成年人矩阵或行列式,但是无论如何我都会遇到的问题将变得显而易见。
public class MatrixOperations {
//Note: this method works fine. There are no problems.
public float determinant(float [][] a)
{
float [][] temp_mat;
float res = 0;
//assuming a square matrix
/*If it's a 2X2, then …Run Code Online (Sandbox Code Playgroud)