Thread has been deleted
Last comment
Turn around chart help c# pros
voltera | 
Finland Manniiii 
Im trying to write c# program that turns chart around for example t[0] becomes t[5] and t[5] becomes t[0] Here is what I tried but this isnt working int i = 0; int o = 0; int j = 5; while (i < t.Length) { t[i]=t[j]; t[j]=t[o]; i++; j--; o++; }
2021-10-17 18:19
Topics are hidden when running Sport mode.
It isnt a real program, more of a practicing thing so its not that serious
2021-10-17 18:20
make a new chart. from what i know u cant assign t[j]'s value to t[i] like that in those languages.
2021-10-17 18:21
5 replies
you can
2021-10-17 18:24
4 replies
just input those values to a new array
2021-10-17 18:25
3 replies
It has to be a loop
2021-10-17 18:26
2 replies
yea, that can be done in a loop
2021-10-17 18:27
1 reply
I dont know if c# has arrays
2021-10-17 18:29
#4
 | 
Spain t3mg
idk men(
2021-10-17 18:25
Iterare i from 0 to halflen-1: Swap array[i] with array[len-1-i] (with auxiliary variable if needed idk c#)
2021-10-17 18:33
4 replies
Idk what any of that means, not sure if thats aplicable to c#
2021-10-17 18:38
3 replies
Okay, let me try to write it (I never wrote c# in my life so beware) int length = t.Length; int halfLength = t.Length / 2 - 1; int aux = 0; for(i=0; i<halfLength; i++) { aux = t[i]; t[i] = t[lenght-1-i]; t[lenght-1-i] = aux; } Let me know if you can make it work.
2021-10-17 19:42
2 replies
name i doesnt exist in current context
2021-10-17 20:02
1 reply
Sorry, I am used to python where you don't need to specify the type of the variables. So, either do i=0 above, or you can inline it directly into the for, which is more elegant and lets i only serve the local scope of the for function, like this: for(int i=0;i<halfLength;i++){ ... }
2021-10-17 20:41
Here is the output begin : 23, 45, 12, 9, 3, 7 end: 7, 3, 9, 9, 3, 7 It should be 7, 3, 9, 12, 45, 23 but it not working
2021-10-17 18:41
#13
 | 
Poland Hanse
Is there any reason not to not make mirror table and just assign it's values to original table in different order?
2021-10-17 19:44
1 reply
idk about any of that, what i wrote is roughly what it should look like but its missing something to make it work maybe couple lines of code should be different
2021-10-17 20:16
you only need to loop the first half, since in one passage you are changing two values using the array 23, 45, 12, 9, 3, 7, like in #11, i did in C(yes, its different, but you can use the logic) #include <stdio.h> int main() { int array[6] = {23, 45, 12, 9, 3, 7}; int i, aux, arraySize; arraySize = 6; //notice the i<3 for a array of 6 elements for(i=0;i<3;i++){ aux = array[i]; array[i] = array[(arraySize-1)-i]; array[(arraySize-1)-i] = aux; } for(i=0;i<6;i++){ printf("%d\n", array[i]); } return 0; }
2021-10-17 20:03
5 replies
ompile error Tauno1a.cs(33,10): error CS0650: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type. Tauno1a.cs(33,11): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression) Tauno1a.cs(51,1): error CS1022: Type or namespace definition, or end-of-file expected 001 using System; 002 005 public class Tauno6 006 { 007 public static void Main() 008 { 009 int[] t = { 23, 45, 12, 9, 3, 7 }; 010 Console.WriteLine("Aluksi : " + string.Join(", ", t)); 011 KaannaTaulukko(t); 012 Console.WriteLine("Lopuksi: " + string.Join(", ", t)); 013 } 014 015 016 /// <summary> 020 /// <example> 021 /// <pre name="test"> 022 /// int[] t; 023 /// t = new int[]{$t1}; KaannaTaulukko(t); String.Join(", ",t) === "$t2"; 024 /// 025 /// $t1 | $t2 026 /// ------------------------------------------------ 027 /// 55, 44, 33, 2, 5, 9 | 9, 5, 2, 33, 44, 55 028 /// 23, 45, 12, 9, 3, 7 | 7, 3, 9, 12, 45, 23 029 /// </pre> 030 /// </example> 031 public static void KaannaTaulukko(int[] t) 032 { 033 int array[6] = {23, 45, 12, 9, 3, 7}; 034 int i, aux, arraySize; 035 arraySize = 6; 036 for(i=0;i<3;i++){ 037 aux = array[i]; 038 array[i] = array[(arraySize-1)-i]; 039 array[(arraySize-1)-i] = aux; 040 041 } 042 for(i=0;i<6;i++){ 043 printf("%d\n", array[i]); 044 } 045 046 j--; 047 } 048 } 049 050 051 } 052
2021-10-17 20:18
it's probably like int[] array = {}. Or int[6] array. Or fucking int* array.
2021-10-17 20:43
If you can please switch to the almighty superior programming language which is Python.
2021-10-17 20:43
2 replies
Im in uni and this course is teaching c#, not to mention employers rarely ask for python knowledge, usually its c# or c++
2021-10-17 21:22
it's probably not this type of c# you'll be doing on a job that does c#. It's usually the .NET framework that's used for backend services, so if you wanna go for a c# job you need to get into that. There are plenty of Python jobs but they are more niched.
2021-10-17 21:29
#22
 | 
United States qoietsammy
from what I can tell you are reversing the array twice by looping until i = the length of the array. You could either copy the values you want over into a new array, and keep the loop the way it is, or only loop until you reach half of the array.
2021-10-17 21:27
2 replies
#23
 | 
United States qoietsammy
granted I don't know c# but I do know a fair bit about java and python and java is pretty similar. does c# allow for loops?
2021-10-17 21:28
#24
 | 
United States qoietsammy
#11 just confirmed that you are indeed reversing twice. You reach the halfway point and then your loop starts copying the first half of your new array into the second half
2021-10-17 21:29
you have to make a new arrays, this is a typical problem with loops and arrays.
2021-10-17 21:31
Login or register to add your comment to the discussion.