Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void urutkan(a, n) int a[];
- int n;
- {
- int i, j, tampung;
- for (i = 0; i < n - 1; ++i)
- for (j = i + 1; j < n; ++j)
- if (a[i] > a[j])
- {
- tampung = a[i];
- a[i] = a[j];
- a[j] = tampung;
- }
- }
- void median(a, n) int a[];
- int n;
- {
- double tengah;
- // int b;
- if (n % 2 == 0)
- {
- tengah = (a[(n - 1) / 2] + a[((n - 1) / 2) + 1]) / 2;
- printf("\nnilai tengahnya adalah = %.2f", tengah);
- }
- else
- {
- tengah = a[n / 2];
- printf("\nnilai tengah adalah = %.2f", tengah);
- }
- }
- void inputdata(int a[], int n)
- {
- int i;
- for (i = 0; i < n; i++)
- {
- printf("data ke-%d = ", i + 1);
- scanf("%d", &a[i]);
- }
- }
- tampilkan(int a[], int n)
- {
- int i;
- for (i = 0; i < n; i++)
- printf("%d\t", a[i]);
- }
- void main()
- {
- int b[100], x;
- float tengah;
- system("cls");
- printf("Masukan jumlah data ? ");
- scanf("%d", &x);
- inputdata(b, x);
- printf("\n");
- printf("Data yang di inputkan = ");
- tampilkan(b, x);
- printf("\n");
- urutkan(b, x);
- printf("\ndata setelah diurutkan = \n");
- tampilkan(b, x);
- median(b, x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement