Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- void transform(float** arr, float* v, int m, int n);
- void matInput(float **mas, int m, int n);
- void matOutput(float **mas, int m, int n);
- void swap(float *a, float *b);
- void cleanMas(float **mas, int m, int n);
- void matSort(float **mas, int m, int n);
- void reverse(float** mat, int m, int n);
- int main(){
- int n, m; //размерность
- printf("Enter N and M: "); //ввод размерности и выделение памяти
- do{
- scanf("%d%d", &n, &m);
- if (n < 0 || m < 0 )
- printf("wrong input! Try again: ");
- } while (n < 0 || m < 0);
- float* v = new float [n * m];
- float** mas = new float* [m]; //выделение памяти под массив
- transform(mas, v, m, n);
- matInput(mas, m, n);
- printf("\nYour matrix:\n");
- matOutput(mas, m, n);
- matSort(mas, m, n);
- reverse(mas, m, n);
- printf("New matrix:\n");
- matOutput(mas, m, n);
- cleanMas(mas, m, n); //освобождение памяти
- getch();
- return 0;
- }
- void transform(float** arr, float* v, int m, int n)
- {
- for (int i = 0; i < m; i++)
- arr[i] = v + i*n;
- }
- void matInput(float **mas, int n, int m)
- {
- printf("Enter your matrix:\n");
- for (int i = 0; i<n; i++)
- for (int j = 0; j<m; j++)
- scanf("%f", &mas[i][j]);
- }
- void matOutput(float **mas, int m, int n)
- {
- for (int i = 0; i<m; i++)
- for (int j = 0; j<n; j++)
- if ( j == n-1)
- printf("%6.2f\n", mas[i][j]);
- else
- printf("%6.2f ", mas[i][j]);
- printf("\n");
- }
- void swap(float *a, float *b)
- {
- float temp = *a;
- *a = *b;
- *b = temp;
- }
- void cleanMas(float **mas, int m, int n)
- {
- delete []*mas;
- delete []mas;
- }
- void matSort(float **mas, int m, int n)
- {
- for (int i = 0; i < m*n-1; i++)
- for (int j = i+1; j < m*n; j++)
- if (mas[0][i] > mas[0][j])
- swap(&mas[0][i], &mas[0][j]);
- }
- void reverse(float** mas, int m, int n)
- {
- for (int i = 1; i < m; i+=2)
- for (int j = 0; j < n/2; j++)
- swap(&mas[i][j], &mas[i][n - j - 1]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement