Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double m[3][3];
- for (i=0; i<ROWLENGTH; ++i){
- double temp;
- temp = m[r2][i];
- m[r2][i] = m[r1][i];
- m[r1][i] = temp;
- }
- double **m;
- m = malloc(sizeof(double*)*NUMROWS);
- /* put error checking here */
- for (i=0; i<NUMROWS; ++i){
- m[i] = malloc(sizeof(double)*ROWLENGTH);
- /* error checking again */
- }
- double *temp;
- temp = m[r2];
- m[r2] = m[r1];
- m[r1] = temp;
- double r[3], q[3] = { 1, 2, 3 };
- r = q; /* ERROR */
- typedef struct { double r[ROWLENGTH] } row;
- row m[NUMROWS] = { {1, 2, 3}, {4, 5, 6}, {7, 8 9}};
- row temp = m[2];
- m[2] = m[1];
- m[1] = temp;
- typedef int Row[3];
- Row Matrix[3];
- Row Temp;
- memcpy(Temp, Matrix[0], sizeof(Row));
- memcpy(Matrix[0], Matrix[1], sizeof(Row));
- memcpy(Matrix[1], Temp, sizeof(Row));
- int x[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
- for (int i=0; i<3; i++) {
- int temp = x[0][i];
- x[0][i] = x[1][i];
- x[1][i] = temp;
- }
- typedef struct {int m[3];} Row;
- typedef int RowAccess[3];
- main()
- {
- Row tmp,row[]={{1,2,3},{4,5,6},{7,8,9}};
- RowAccess *rowa=row;
- tmp=row[0];
- row[0]=row[1];
- row[1]=tmp;
- /* easy access to matrix here: (is this what you want?) */
- rowa[0][0]=0;
- rowa[0][1]=1;
- ...
- return 0;
- }
- auxiliary = a ;
- a = b ;
- b = auxiliary ;
- a ^= b ;
- b ^= a ;
- a ^= b ;
- int swap (int *a , int *b){
- (*a)^=(*b);
- (*b)^=(*a);
- (*a)^=(*b);
- return 0;
- }
- #define ROW_COUNT 5
- #define COLUMN_COUNT 5
- ....
- int a[ROW_COUNT][COLUMN_COUNT];
- printf("nSwap Row: "); scanf("%d", &swp1) ; // first row index
- printf("With Row: "); scanf("%d", &swp2); // second row index
- for (j = 0 ; j < COLUMN_COUNT ; j++){
- swap( &a[swp1][j] , &a[swp2][j] );
- }
- #include "stdio.h"
- #include "conio.h"
- #define ROW_COUNT 5
- #define COLUMN_COUNT 5
- int swap (int *a , int *b){
- (*a)^=(*b);
- (*b)^=(*a);
- (*a)^=(*b);
- return 0;
- }
- int main(){
- int i, j ;
- int swp1, swp2 ;
- int a[ROW_COUNT][COLUMN_COUNT];
- // Create ( ROW_COUNT X COLUMN_COUNT ) random matrix
- for (i = 0 ; i < ROW_COUNT ; i++ )
- for (j = 0 ; j < COLUMN_COUNT ; j++ ) a[i][j] = rand();
- // Display matrix before row swap
- for (i = 0 ; i < ROW_COUNT ; i++ ){
- for (j = 0 ; j < COLUMN_COUNT ; j++ ) printf("%dt",a[i][j]);
- printf("n");
- }
- // Elements to be swapped
- printf("nSwap Row: "); scanf("%d", &swp1) ; // first row index
- printf("With Row: "); scanf("%d", &swp2); // second row index
- // Swapping right here
- for (j = 0 ; j < COLUMN_COUNT ; j++){
- swap( &a[swp1][j] , &a[swp2][j] );
- }
- // Display once again
- printf("n");
- for (i = 0 ; i < ROW_COUNT ; i++ ){
- for (j = 0 ; j < COLUMN_COUNT ; j++ ) printf("%dt",a[i][j]);
- printf("n");
- }
- getch();
- return 0;
- }
- temprow = row[1];
- row[1] = row[0];
- row[0] = temprow;
- #include <algorithm>
- int A[][] = {{1,2,3},{4,5,6},{7,8,9}};
- swap(A[0],A[2]); //swaps first and last row
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement