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
I tried to print every pair of element while it's factorial
language: language-c
#include<studio library>//
in main function I try to store 2D array which size is
a[1][3];
And, I write these code
integer a[1][3] = {1,2,3,4,5};
and I find factorial of 5 = 120
I have to print three element together
it is possible 120 times;
so ,I can try 120 different value using print function function
in a[1][3];
like this output
1,2,3 is 1.
1,2,4 is 2.
1,2,5 is 3.
1,3,4 is 4.
1,3,5 up to 120
I want to know that how to store value in 2D array
but the array is a[1][3]
You may set the values of j and k to be "i-dependent" but they are not updating their value, you should add a j++,k++ next to the i++
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 1 year ago.
The community is reviewing whether to reopen this question as of 1 year ago.
Improve this question
So I created an array with 100 variables using Enumerable.Range. The data type is limited to Int32.
Problem
How can I create the same array with SByte?
Am I right in thinking I would need to use a loop to create and index the variables?
I have looked around online and most results touch on declaring counting variables for the loop but not using a loop to declare variables
Just cast them:
SByte[] array = Enumerable.Range(0, 100).Select(i => (SByte) i).ToArray();
note that SByte is not cls compliant, you might want to use short instead.
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 2 years ago.
Improve this question
`
for(int i=0;i<jagged.Length;i++)
{
for(int j=0;j<jagged[i].Length;i++)
{
jagged[i][j] = Convert.ToInt32(Console.ReadLine());
}
}
`
i want this piece of code to take 2 score inputs in jagged[0] and 3 score inputs in jagged1 but it is taking 5 inputs in both the cases.
jagged array input problem
For "n" number of teams with "at" attempts, i want to store the scores of these teams in "at" attempts in the jagged array
example :
if used inputs n = 2 and at= 2 for the first team.
a jagged[2][2] should be created,
i want to store the scores in this way-
jagged[0] should be = new int[2]; (which i did at line 15)
The lines starting from 21 are supposed to store these scores,
but when i run the program, it takes input of scores more than the Length.
What i want is -
jagged[0][0] should store the first score input
jagged0 should store the second score input
and it should stop there. but it doesnt , it takes input 3 more times.(5 times total)
Similarly, the attempts for 2nd team is input as 3 and still it is taking the input 2 more times (5 times total)
You are using a triple cicle, but you just need 2. Remove the k for cicle,and change the condition for the j cicle to j <jag[i].Length
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 3 years ago.
Improve this question
I have a method that pseudo-randomly encrypts a byte array. I would like to convert the encrypted byte-array to a C# int (4 bytes), while observing a user-specified lower and upper bound (e.g. give me a number between 1 and 10)
What is the most secure and performant way of achieving this?
You could use System.ByteConverter.ToInt32(arr, start_index).
From your description of the array, the start index would likely be zero.
I am not sure what you mean by upper and lower bound, but if you mean you want a random number, you could use a variety of functions to get a value in between the two numbers. If you have semi-uniform distribution, the modulus function would work nicely. In that case, your random number would simply be lowerBound + (System.ByteConverter.ToInt32(arr, start_index) % (upperBound - lowerBound)).
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 4 years ago.
Improve this question
I have the following question: How could I save what is in a texbox with numbers, separated from each other by commas, which are entered by the user in an array (vector)? The maximum number of numbers that can be entered is 3, and separated by commas, since I need to make a cross product of vectors (Product point). In advance thanks for the help.
You can simply use "split" and it will create the array.
var arrayList = yourTexbox.Text.split(",");
Give textboxes name like txt[1], txt[2], txt[3] and receive that from backend as array which contains value of textbox1 in 1th index , textbox2 in 2nd index etc
Use Regex.Matches with a pattern that only matches sets of 3
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
Im trying to do exactly what the title says
int[] weeks = {};
weeks[weeks.Length]=1;
this doesnt work. There is also no .Add Method.
Any ideas? or is this not possible
Line 1 declares and initializes a new 1-dimensional array of int without specific size.
Line 2 resizes the array (weeks) to its actual size, plus 1.
Line 3 assigns the value 1 to the element at the last position (that we created in Line 2)
Remember: int[5] weeks; -> to access last element you have to use index 4 -> weeks[4] = 1
int[] weeks = {};
Array.Resize(ref weeks,weeks.Length + 1);
weeks[weeks.Length - 1]=1;
Arrays in C# by definition are of a fixed size, and cannot be dynamically expanded.
I would suggest using a List<>, as they can be dynamically expanded, much like vectors in other programming languages.
List<int> weeks = new List<int>();
weeks.add(1);
See more here.
First of all there is no such thing razor array. Razor is a view engine and array is a data structure.
Arrays have fixed length so if you declare an array with the length of 5:
int[] weeks = new int[5];
Trying to add an element to a fifth place will result in IndexOutOfRangeException
If you need some data-structure with variable size you could look at all the objects that implement IList interface for example a List, an ArrayList and others.
IList interface also defines Add method that you requested.