Advertisement
Josif_tepe

Untitled

Feb 9th, 2021
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int main()
  6. {
  7. int n;
  8. scanf("%d", &n);
  9. double mat[101][101];
  10. for(int i = 0; i < n; i++) {
  11. for(int j = 0; j < n; j++) {
  12. scanf("%lf", &mat[i][j]);
  13. }
  14. }
  15. double X = 0.0, Y = 0.0;
  16. for(int i = 0; i < n; i++) {
  17. for(int j = 0; j < i; j++) {
  18. X += mat[i][j];
  19. }
  20. }
  21. for(int i = 0; i < n; i++) {
  22. for(int j = n - i; j < n; j++) {
  23. Y += mat[i][j];
  24. }
  25. }
  26. double B[101][101];
  27. for(int i = 0; i < n; i++) {
  28. for(int j = 0; j < n; j++) {
  29. B[i][j] = 0.0;
  30. }
  31. }
  32. for(int i = 0; i < n; i++) {
  33. for(int j = 0; j < n; j++) {
  34. if(i == j) {
  35. B[i][j] = X;
  36. }
  37. }
  38. }
  39. for(int i = 0; i < n; i++) {
  40. for(int j = 0; j < n; j++) {
  41. if(i + j == n - 1) {
  42. B[i][j] = Y;
  43. }
  44. }
  45. }
  46. if(n % 2 == 1) {
  47. B[n / 2][n / 2] = X + Y; // ako elementot pripaga i na dvete dijagonali
  48. }
  49. for(int i = 0; i < n; i++) {
  50. for(int j = 0; j < n; j++) {
  51. printf("%f ", B[i][j]);
  52. }
  53. printf("\n");
  54. }
  55. return 0;
  56. }
  57. /*
  58. 4
  59. 1 2 3 4
  60. 5 6 7 8
  61. 9 10 11 12
  62. 13 14 15 16
  63. */
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement