Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* BISMILLAHIR-RAHMANIR-RAHIM
- ____________________________________
- | |
- | SHANTO_SUST_SWE-19_029 |
- |____________________________________|
- */
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <stdlib.h>
- #include <time.h>
- #define debug 0
- int r, c;
- void reverse_array(int x[r][c], int **y, int r, int c)
- {
- int i, j, k;
- for(i = 0; i < r; i++){
- for(j = 0, k = c - 1; j < c; j++, k--){
- y[i][k] = x[i][j];
- }
- }
- }
- int main()
- {
- scanf("%d %d", &r, &c);
- int ara[r][c];
- int i, j;
- /// (Line no 36 & 37) :: used them for using random number
- time_t t;
- srand((unsigned) time(&t));
- for(i = 0; i < r; i++){
- for(j = 0; j < c; j++){
- ara[i][j] = rand() % 10; ///taking random number instead of scanning, you can custom your input by scanf()
- }
- }
- /// (Line no 47-53) - by these lines i have declared the memory needed for rev_ara
- int **rev_ara;
- rev_ara = (int **) malloc(sizeof(int) * r); //using this line, we are declaring how many rows to be needed
- for(i = 0; i < r; i++){
- rev_ara[i] = (int *) malloc(sizeof(int) * c); // using this loop, we are declaring how many columns will be in every row
- }
- printf("Random Array:\n");
- for(i = 0; i < r; i++){
- for(j = 0; j < c; j++){
- printf("%d ", ara[i][j]);
- }
- printf("\n");
- }
- printf("\n");
- reverse_array(ara, rev_ara, r, c);
- printf("Reversed Random Array:\n");
- for(i = 0; i < r; i++){
- for(j = 0; j < c; j++){
- printf("%d ", rev_ara[i][j]);
- }
- printf("\n");
- }
- return 0;
- }
- //ALHAMDULILLAH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement