Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester
{
public class Program
{
public static void Fill(int [,]matr, int n, int m)
{
Random rand = new Random();
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
matr[i,j] = rand.Next(0, 133);
}
}
}
static void Swap<T>(ref T a, ref T b)
{
T c = a;
a = b;
b = c;
}
public static void Print(int [,]matr, int n, int m)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
Console.Write(matr[i,j] + "\t");
}
Console.WriteLine();
}
}
public static void Sort(int [,]matr, int n, int m)
{
for(int j=0;j<m;j++)
{
for(int i=0;i<n;i++)
{
for(int z=0;z<n;z++)
{
if(matr[i,j] < matr[z,j])
{
Swap(ref matr[i,j], ref matr[z,j]);
}
}
}
}
}
public static void Main(string[] args)
{
Console.WriteLine("n = ");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("m = ");
int m = Convert.ToInt32(Console.ReadLine());
int [,]matr = new int[n,m];
Fill(matr, n, m);
Console.WriteLine("Matrix");
Print(matr, n, m);
Sort(matr, n, m);
Console.WriteLine("After sorting");
Print(matr, n, m);
}
}
}
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more