Advertisement
informaticage

Matrix and pitagorean table

Aug 18th, 2022 (edited)
1,131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. /*
  2.   Data: 18/08/2022
  3.   Programma:
  4.     Scrivi un programma che riempe una matrice con la tavola pitagorica dei
  5.   primi 10 numeri e la visualizza sullo schermo.
  6. */
  7. #include <stdio.h>
  8.  
  9. #define LEN 10
  10.  
  11. void loadMatrix(int matrix[][LEN]) {
  12.   for (size_t i = 0; i < LEN; i++) {
  13.     for (size_t j = 0; j < LEN; j++) {
  14.       matrix[i][j] = (i + 1) * (j + 1);
  15.     }
  16.   }
  17. }
  18.  
  19. void printMatrix(int matrix[][LEN]) {
  20.   for (size_t i = 0; i < LEN; i++) {
  21.     for (size_t j = 0; j < LEN; j++) {
  22.       // Lascia 3 spazi per motivi di formattazione dell'output
  23.       printf("%3.d ", matrix[i][j]);
  24.     }
  25.  
  26.     printf("\n");
  27.   }
  28. }
  29.  
  30. int main() {
  31.   int M[LEN][LEN];
  32.   loadMatrix(M);
  33.   printMatrix(M);
  34.   return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement