Advertisement
shegues

magicSquare.c

Jan 30th, 2021
1,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include<stdio.h>
  2. int main(void)
  3. {
  4.     int a, b, c, d, e, f, g, h, i, l, m, n, o, p, q, r;
  5.     printf("Enter th enumber from 1 to 16 in any order: \n");
  6.     scanf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &g, &h, &i, &l, &m, &n, &o, &p, &q, &r);
  7.     printf("%d %d %d %d\n", a, b, c, d);
  8.     printf("%d %d %d %d\n", e, f, g, h);
  9.     printf("%d %d %d %d\n", i, l, m, n);
  10.     printf("%d %d %d %d\n", o, p, q, r);
  11.     printf("\n");
  12.     printf("Row sums: %d %d %d %d\n", (a+b+c+d), (e+f+g+h), (i+l+m+n), (o+p+q+r));
  13.     printf("Column sums: %d %d %d %d\n", (a+e+i+o), (b+f+l+p), (c+g+m+q), (d+h+n+r));
  14.     printf("Diagonal sum: %d %d\n", (a+f+m+r), (d+g+l+o));
  15.     return 0;
  16.  
  17.  
  18.  
  19.  
  20.  
  21. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement