• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Diagonal_Difference.c

a guest Apr 19th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <assert.h>
2. #include <limits.h>
3. #include <math.h>
4. #include <stdbool.h>
5. #include <stddef.h>
6. #include <stdint.h>
7. #include <stdio.h>
8. #include <stdlib.h>
9. #include <string.h>
10.
11. int i = 0;
12. int j = 0;
13.
14. void HasilDiagonal(int **data, int index) {
15.   int kiri = 0;
16.   int kanan = 0;
17.   int total = 0;
18.
19.   for (i = 0; i < index; i++) {
20.     for (j = 0; j < index; j++) {
21.       if (i == j) {
22.         kiri += data[i][j];
23.       }
24.     }
25.   }
26.
27.   for (i = 0; i < index; i++) {
28.     for (j = index; j >= 0; j--) {
29.       kanan += data[i][j];
30.     }
31.   }
32.
33.   if (kiri > kanan) {
34.     total = kiri - kanan;
35.     printf("%d", total);
36.   }
37.   if (kanan > kiri) {
38.     total = kanan - kiri;
39.     printf("%d", total);
40.   }
41. }
42.
43. int main() {
44.   int n = 0;
45.   scanf("%d", &n);
46.   int **arr = (int **)malloc(sizeof(int) * n * n);
47.   for (i = 0; i < n; i++) {
48.     for (j = 0; j < n; j++) {
49.       scanf("%d", &arr[i][j]);
50.     }
51.   }
52.   HasilDiagonal(arr, n);
53.   free(arr);
54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top