Pavle_nis

Matrice3

Dec 29th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. // Matrice10.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdio.h>
  6.  
  7. int main()
  8. {
  9.     int a[20][20], i, j, n, k, pom;
  10.     printf("Unesi n");
  11.     scanf_s("%d", &n);
  12.     for (i = 0; i < n; i++) {
  13.         for (j = 0; j < n; j++) {
  14.             scanf_s("%d", &a[i][j]);
  15.         }
  16.     }
  17.     printf("Pre sortiranja\n");
  18.     for (i = 0; i < n; i++) {
  19.         for (j = 0; j < n; j++) {
  20.             printf("%d", a[i][j]);
  21.         }
  22.         printf("\n");
  23.     }
  24.     for (i = 0; i < n; i++)
  25.     {
  26.         for (j = 0; j < n; j++)
  27.         {
  28.             for (k = j+1; k < n; k++)
  29.             {
  30.                 if (a[i][j] > a[i][k])
  31.                 {
  32.                     pom = a[i][j];
  33.                     a[i][j] = a[i][k];
  34.                     a[i][k] = pom;
  35.                 }
  36.             }
  37.         }
  38.     }
  39.     printf("Posle sortiranja\n");
  40.     for (i = 0; i < n; i++) {
  41.         for (j = 0; j < n; j++) {
  42.             printf("%d", a[i][j]);
  43.         }
  44.         printf("\n");
  45.     }
  46.     system("pause");
  47. }
Advertisement
Add Comment
Please, Sign In to add comment