Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. // cw01.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "conio.h"
  6. #include "time.h"
  7. #include <iostream>
  8.  
  9. int _tmain(int argc, _TCHAR* argv[])
  10. {
  11.     srand(time(NULL));
  12.     int t[5][5];
  13.     int i,j;
  14.     i=0;
  15.     while(i<5){
  16.         j=0;
  17.         while(j<5){
  18.             t[i][j]=rand()%10 -0;
  19.             j++;
  20.         }
  21.         i++;
  22.     }
  23.     printf("Wszystkie elementy:\n");
  24.     for(i=0;i<5;i++){
  25.         for(j=0;j<5;j++){
  26.             printf("%2d",t[i][j]);
  27.         }
  28.         printf("\n");
  29.     }
  30.     printf("\nElementy NA przekatnej:\n");
  31.     for(i=0,j=0;i<5,j<5;i++,j++){
  32.             if(i==j){
  33.                 printf("%2d",t[i][j]);
  34.             }
  35.     }
  36.     printf("\n");
  37.     printf("\nElementy NAD glowna przekatna:\n");  
  38.     for(i=0;i<4;i++){
  39.         for(j=i+1;j<5;j++){
  40.             printf("%2d",t[i][j]);
  41.         }
  42.         printf("\n");
  43.     }
  44.     printf("\nElementy POD glowna przekatna:\n");
  45.     for(i=0;i<5;i++){
  46.         for(j=0;j<5;j++){
  47.             if(j<i){
  48.                 printf("%2d",t[i][j]);
  49.             }
  50.         }
  51.         printf("\n");
  52.     }
  53.     _getch();
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement