Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате |
Форум программистов > Общие вопросы по .NET и C# > помогите с задачей на C# c массивами |
Автор: ChildOfLight 11.11.2011, 23:28 |
дана матрица m*n поменять местами столбец с номером 1 и последний из столбцов, содержащих только положительные элементы Если таких столбцов нет,то вывести матрицу без изменений массив задаю так, а дальше проблемы=( Console.WriteLine("введите размерность массива"); Console.Write("n="); m=int.Parse(Console.ReadLine()); Console.Write("m="); n=int.Parse(Console.ReadLine()); int[,]a=new int[m,n]; for(int i=0;i<m;++i) for(int j=0;j<n;++j) { Console.Write("a[{0}],{1}]=",i,j); a[i,j]=int.Parse(Console.ReadLine()); } return a; |
Автор: ChildOfLight 12.11.2011, 00:48 |
вот программа, но она не работает,не подскажите где ошибка? class Program { static int[,] Input() { Console.WriteLine("введите размерность массива"); int m = int.Parse(Console.ReadLine()); int n = int.Parse(Console.ReadLine()); int[,] a = new int[m, n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) { Console.Write("a[{0}][{1}]=", i, j); a[i, j] = int.Parse(Console.ReadLine()); } return a; } static bool polozit(int[,] m, int c) { for (int j = 0; j < m.GetLength(0); j ++) if (m[j , c] < 0) return false; return true; } static void Change(int[,] m, int c1, int c2) { for (int j = 0; j < m.GetLength(0); j --) { int x = m[j , c1]; m[j , c1] = m[j , c2]; m[j , c2] = x; } } static void Main(int[,] m) { for (int j = m.GetUpperBound(1); j > 0; j ++) if (polozit(m, j )) { Change(m, 0, j ); break; } } } } |
Автор: Brilona 14.11.2011, 17:04 | ||
Почему в этом методе используется "j --", а не "j ++"?
|