Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm working on windows form application and I have homework to calculate the square of 5 numbers in one textbox and I have to put all 5 numbers in different lines
I expect the results to be like this,
you enter 5 numbers in each line
4
9
16
25
and get them in one single message box saying the results like
2, 3, 4, 5
Pass the Textbox Text into the function and It will Print all the SqureRoot of the Numbers
private void squreRootFinder(string textBox)
{
string[] numbers = textBox.Split('\n');
string data = "";
for (int i = 0; i < numbers.Length; i++)
{
data += Math.Sqrt(Convert.ToInt32(numbers[i])) + " ";
}
MessageBox.Show(data);
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
Could someone help me why do i get true only if the numbers are the same? I need to find out if the second input is in the first one. True/false
int[] firstNumber;
firstNumber = new int[10];
firstNumber[0] =
Convert.ToInt32(Console.ReadLine());
int secondNumber =
Convert.ToInt32(Console.ReadLine()) ;
Console.WriteLine(firstNumber.Contains(secondNumber));
Edit. I need to get true for ex.:firstNumber 5214 and secondNumber 4
how can i get true for 5432(firstNum) and 3(secondNum)
Use strings instead of integers, which will use string.Contains instead of Array.Contains:
string firstNumber = Console.ReadLine();
string secondNumber = Console.ReadLine();
Console.WriteLine(firstNumber.Contains(secondNumber));
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Does anyone know a logic to divide a number randomly? I need to do this in C#, but it might just be logic here.
Example:
I want to split 10 = 3 + 4 + 1 + 2
I want to split 30 = 2 + 5 + 8 + 4 + 6 + 5
Pseudo Code:
myNumber = 30; //Number to split
int maximumValue = myNumber; //Maximum value we can get with rand()
int totalValue = 0; //Save our total
while(totalValue < myNUmber)
{
newSplitNumber = rand(0, maximumValue); //Use as needed
totalValue+= newSplitNumber; //Update our total
maximumValue = myNumber - totalValue; //Update our maximum on next iteration
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have this code that helps me getting information from texts files , the problem is that i cant get to add all the strings founds in the texts files into one int.
in the first Entrada.txt i have a 23 and in the second one i have 45.
How can i add those 2 numbers together?
foreach(var impressora in ListaImp)
{
var Entrada = File.ReadAllText(impressora + #"\Entrada.txt");
MessageBox.Show("Entrada : " + Entrada);
}
Output: 2345.
I want it to be 23 + 45 = 68
You can do this:
int sub = 0;
foreach(var impressora in ListaImp)
{
var Entrada = File.ReadAllText(impressora + #"\Entrada.txt");
sub += int.Parse(Entrada);
}
MessageBox.Show(sub.ToString());
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I enter the value in textbox:
1,2,3,4,5,6,7...
How to into to int array or list and show value display ???
And stop when a user enters the wrong consecutive 3 times or total error of 5
//textbox is your textbox controls' name
string[] content = textbox.Text.Split(',');
//use linq convert stringp[] to int[]
int[] nums = (from num in content
select int.Parse(num)).ToArray();
I don't understand the last part of your question (the bit about stopping when a user enters something wrong... I guess you'd have to define "wrong" in this context). Regardless, the following code should take values entered into a text box (let's call it txtNumbers) and put it in an array of ints.
string[] splitContent = txtNumbers.Text.Split(new char[] { ',' });
int[] nums = new int[splitContent.Length];
for (int i = 0; i < splitContent.Length; i++)
{
nums[i] = Int32.Parse(splitContent[i]);
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want an auto-numbering class in c# which would generate numbers of 8 digit length in the following format i.e. 1A2B3C4D..one number followed by one letter.Any suggestions??
Pseudocode for generating such string:
String result = "";
for ( int i = 0; i < 8 ; i++)
{
if ( i % 2 == 0)
{
// random(a,b) returns random value between or equal to a-b
result.append(random(0,9).toString());
}
else
{
result.append(random(65,90).toChar()); // Generating a random value between 65-90 (A-Z in ascii)
}
}
Edit:
Or as Sayse suggested:
String result = "";
for (int i = 0; i< 4; i++)
{
result.append(random(0,9).toString());
result.append(random(65-90).toChar());
}