C# 2005

Associate
Joined
1 Apr 2011
Posts
22
Location
London
Hi all, I'm still very new to C#, and right now I have a project, where I am creating a program.

What I need to do is declare three arrays namely A1, A2, and A3 each of size k.
Assign random values to array A1.
I want to write a C# program in microsoft visual studio 2005 using arrays and function to implement the following:
A2 (0) = A1 (k), A2 (1) = A1 (k-1), and so on….

A3 (k) = A1(k) if A1(k)>A2(k),

= A2 (k) otherwise
Output all the elements of arrays A1, A2 and A3

Please if you could help me, would be much appreciated.

Many thanks

Adam
 
What have you got so far?

We're usually not happy to do other's coursework for them, but happy to help with a particular problem you are stuck on.
 
Hi the problem is I dont know where to start im new to c# maybe a push in the right direction would help me grasp the whole concept.

thanks for your response

Adam
 
How far have you got?

Starting from the start you'll need to create a new project. A command line app would be ideal for this as you don't need to worry about creating a UI.

Check out this guide: http://msdn.microsoft.com/en-us/library/0wc2kk78(v=vs.90).aspx
It's for VS 2008, but the principles are the same.

Has your lecturer not given you any materials or a guide to work with?
 
No materials provided thats why im a bit lost on what to do and how to start. Thanks for the input very much appreciated!
 
I managed to get this, if someone could let me know if what iv done is right pls it would much help.

static void Main(string[] args)
{
const int k = 10;

int[] A1 = new int[k];
int[] A2 = new int[k];
int[] A3 = new int[k];

for (int i = 0; i < k; i++)
{
A1 = i + 1;
}

for (int i = 0; i < k; i++)
{
A2 = A1[k-1-i];
}

for (int i = 0; i < k; i++)
{
A3 = (A1 > A2) ? A1 : A2;
}

for (int i = 0; i < k; i++)
{
Console.WriteLine("A1[" + i + "] = " + A1);
Console.WriteLine("A2[" + i + "] = " + A2);
Console.WriteLine("A3[" + i + "] = " + A3);
Console.WriteLine("");
}
}
}
}
 
Can't test it at the mo, but from the looks of it you should be able to put it all into one loop which should speed up the process:
Code:
static void Main(string[] args) {
	const int k = 10;

	int[] A1 = new int[k];
	int[] A2 = new int[k];
	int[] A3 = new int[k];

	for (int i = 0; i < k; i++) {
		A1[i] = i + 1;
		
		A2[i] = A1[k-1-i];
		
		A3[i] = (A1[i] > A2[i]) ? A1[i] : A2[i];
		
		Console.WriteLine("A1[" + i + "] = " + A1[i]);
		Console.WriteLine("A2[" + i + "] = " + A2[i]);
		Console.WriteLine("A3[" + i + "] = " + A3[i]);
		Console.WriteLine("");
	}
}
 
Back
Top Bottom