Advertisement
KvArt

Transponovanje matrice

Aug 16th, 2022
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define N 100
  4.  
  5. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  6.  
  7. void main()
  8. {
  9.     while(1)
  10.         {
  11.            
  12.             int i,j;
  13.             double b;
  14.             printf("Unesite dimenziju matrice: "); int n; scanf("%d", &n);
  15.             if(n<=0 || n>N) break;
  16.            
  17.             double a[N][N];
  18.              for(i=0;i<n;i++)
  19.              {
  20.                 printf("Unesite elemente %d. vrste: ",i);
  21.                 for(j=0;j<n; scanf("%lf", &a[i][j++]));
  22.              }
  23.            
  24.             for (i=0;i<n-1;i++)
  25.                 for(j=i+1;j<n;j++)
  26.                     {
  27.                         b= a[i][j]; a[i][j] = a[j][i]; a[j][i] = b;
  28.                     }
  29.            
  30.             printf("\nTransponovana matrica izgleda ovako: \n\n");
  31.            
  32.             for (i=0;i<n;i++)
  33.                 {
  34.                 for(j=0;j<n; printf("%6.1lf", a[i][j++]));
  35.                 printf("\n\n");
  36.                 }
  37.            
  38.         }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement