21 Aralık 2010 Salı

matrisin transpoze' nu bulan c sharp programı

Yorum Bırak

a c program that computes the transpose of a matrix


program.cs  class




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{

    class Program
    {
        static void Main(string[] args)
        {
             ArrayConverter con=new ArrayConverter();

            Console.WriteLine(" x dimension:");
            int x=int.Parse(Console.ReadLine());
            Console.WriteLine(" y dimension:");
            int y=int.Parse(Console.ReadLine());
            int s;
            int[,] deneme = new int[x, y];
              Random r = new Random();      //randomla sayı atıyoruz
              int e = 0;
              while ( e < x)
              {
                  for (int z = 0; z < y; z++)
                  {
                      s = r.Next(0,10);

                       deneme[e,z]=s;

                  }
                  e++;

              }



             int i =0;
              while( i < x)
              {
                  for (int z = 0; z < y; z++)
                  {
                      Console.Write(deneme[i,z]);
                      Console.Write(" ");
                  }
                  Console.WriteLine("\n");
                  i++;
              }
              Console.WriteLine("the new  array:");
              con.ReverseAndConvertArray(deneme);

              Console.ReadLine();


        }
    }
}


ArrayConverter class



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class ArrayConverter
    {
        public void ReverseAndConvertArray(int[,] inputArray)
        {
            int a, b;
            a = inputArray.GetLength(0);

            b = inputArray.GetLength(1);
            int[,] jaggedarray = new int[b, a];

            int l = 0 ;
            int y = a - 1;
            if (a != b)
            {

                for (int i = 0; i < a; i++)
                {
                    for (int k = 0; k < b; k++)
                    {
                        jaggedarray[k, l] = inputArray[i, k];

                    }
                    l++;
                }
               int m = 0;
                while ( m < b)
                {
                    for (int z = 0; z < a; z++)
                    {
                        Console.Write(jaggedarray[m, z]);
                        Console.Write(" ");
                    }
                    Console.WriteLine("\n");
                }

            }
            else
            { l = 0;
                int q = 0;
                while (q < a)
                {
                    for (int k = 0; k < b; k++)
                    {
                        jaggedarray[k, l] = inputArray[i, k];

                    }
                    l++;
                    q++;
                }
                for (int i = 0; i < a; i++)
                {
                    for (int z = 0; z < b; z++)
                    {
                        Console.Write(jaggedarray[i, z]);
                        Console.Write(" ");
                    }
                    Console.WriteLine("\n");
                }

            }


        }
    }
}

0 yorum:

Yorum Gönder