Jump to content

matrix programs in C#

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
solarexplode

solarexplode

    Newbie

  • Members
  • Pip
  • 1 posts
hi
i'm very new to the programming. i have two questions related to matrices. Hope somoeone will help me with the code or even pseudo code is fine.

1. A c# function that returns TRUE when a matrix have same elements in anyone of the rows.
eg. 1 2 4
1 1 1
2 2 4
The function for the above matrix should return True otherwise false.

2. A c# function which takes two input values and displays a matrix in the following pattern

input: a,b

a a a a
a a a b
a a b b
a b b b
b b b b

I would appreciate your help

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Given that the matrix will be stored in an array, what do you have so far?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
chandubaba

chandubaba

    Newbie

  • Members
  • Pip
  • 3 posts

solarexplode said:

hi
i'm very new to the programming. i have two questions related to matrices. Hope somoeone will help me with the code or even pseudo code is fine.

1. A c# function that returns TRUE when a matrix have same elements in anyone of the rows.
eg. 1 2 4
1 1 1
2 2 4
The function for the above matrix should return True otherwise false.

2. A c# function which takes two input values and displays a matrix in the following pattern

input: a,b

a a a a
a a a b
a a b b
a b b b
b b b b

I would appreciate your help
1st problem:-
public static bool meth(int[,]arr)
{
	for(int i=0;i<=arr.GetUpperBound(0);i++)
	{
		List<int> ll=new List<int>();
		for(int j=0;j<=arr.GetUpperBound(1);j++)
		{
			ll.Add(arr[i,j]);
		}
		ll.Sort();
		if(ll[0]==ll[ll.Count-1])return true;
	}
	return false;
}// you have to add using System.Collections.Generic; as header for list to work
2nd problem:-
public static void meth(char a,char b)
{
	for(int i=0;i<5;i++)
	{
		for(int j=0;j<5-i-1;j++)
		{
			Console.Write(a+" ");
		}
		for(int j=5-i;j<5;j++)
		{
			Console.Write(b+" ");
		}Console.WriteLine();
	}
}

Edited by Jaan, 23 November 2009 - 07:41 AM.
Please use code tags when you are posting your codes!