Advertisement
davide1409

triangolo_sup.c

Jan 11th, 2022
684
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #define N 5
  3. int main(void){
  4.     int matrix[N][N];
  5.     int coeff = 1;
  6.     for(int i = 0; i<N; i++){
  7.         for(int j = 0; j<N; j++){
  8.             matrix[i][j] = coeff;
  9.             coeff++;
  10.         }
  11.     }
  12.  
  13.     puts("Stampa della matrice completa");
  14.     for(int i = 0; i<N; i++){
  15.         for( int j = 0; j<N; j++){
  16.             printf("%d\t", matrix[i][j]);
  17.         }
  18.         puts("");
  19.     }
  20.  
  21.     puts("\nStampo triangolo superiore");
  22.     for(int i = 0; i<N; i++){
  23.         for( int j = i+1; j<N; j++){
  24.             printf("%d\t", matrix[i][j]);
  25.         }
  26.         puts("");
  27.     }
  28.  
  29.     puts("\nAltro modo di esplorare un triangolo superiore");
  30.     for(int h = 1; h<N; h++){
  31.         for(int i = 0, j = h; i<N-h; i++, j++){
  32.             printf("%d\n", matrix[i][j]);
  33.         }
  34.         puts("");
  35.     }
  36.  
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement