Yachkov

Zadacha1

Jan 15th, 2023 (edited)
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     printf("Author: Teodor Yachkov\n");
  7.     printf("Fak. #251222023, FIT, KPTM, grupa 19b\n");
  8.  
  9.     float A[3][3];
  10.     int i, j;
  11.  
  12.     for (i = 0; i < 3 ;i++)
  13.     {
  14.         for (j = 0; j < 3 ;j++)
  15.         {
  16.             do
  17.             {
  18.                 printf("A[%d][%d]= ", i, j);
  19.                 scanf("%f", &A[i][j]);
  20.             }
  21.             while ((A[i][j] < -999.99) || (A[i][j] > 999.999));
  22.         }
  23.     }
  24.  
  25.     printf("Otpechatvane na vhodni danni\n");
  26.  
  27.     for ( i = 0; i < 3; i++)
  28.     {
  29.         for ( j = 0; j < 3; j++)
  30.         {
  31.             printf("A[%d][%d] = %f ", i,j,A[i][j]);
  32.             printf("\n");
  33.         }
  34.     }
  35.  
  36.     int count = 0;
  37.     int nums;
  38.     for (i = 0; i < 3; i++)
  39.     {
  40.         for (j = 0; j < 3; j++)
  41.         {
  42.             if(A[i][j] > 0)    
  43.             {
  44.                 count++;
  45.             }
  46.         }
  47.     }
  48.  
  49.     int C[count];
  50.     int k = 0;
  51.     for (i = 0; i < 3; i++)
  52.     {
  53.         for (j = 0; j < 3; j++)
  54.         {
  55.             if(A[i][j] > 0)    
  56.             {
  57.                 C[k] = A[i][j];
  58.                 k++;
  59.             }
  60.         }
  61.     }
  62.     for (i = 0; i < count; i++) {
  63.         for (j = 0; j < count-1; j++) {
  64.             if (C[j] > C[j+1]) {
  65.                 int temp = C[j];
  66.                 C[j] = C[j+1];
  67.                 C[j+1] = temp;
  68.             }
  69.         }
  70.     }
  71.     printf("Sorted array: \n");
  72.     for ( i = 0; i < count; i++)
  73.     {
  74.         printf("C[%d] = %d\n", i,C[i]);
  75.     }
  76.     printf("\n");
  77.  
  78.     system("pause");
  79.     return 0;
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment