0% found this document useful (0 votes)
19 views2 pages

FSP 22

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

FSP 22

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Alfian Rama Putra

2440117684

#include <stdio.h>

#include <stdlib.h>

int bubblesort(int arr[], int t){

int tmp;

for(int i=0;i<t;i++){

for(int j=0;j<t-i-1;j++){

if(arr[j] > arr[j+1]){

tmp = arr[j];

arr[j] = arr[j+1];

arr[j+1] = tmp;

int selectionsort(int arr[], int t){

int flg, swp;

for(int i=0;i<t-1;i++){

flg = i;

for(int j=i+1;j<t;j++){

if(arr[flg] > arr[j]){

flg = j;

if(flg != 1){

swp = arr[i];

arr[i] = arr[flg];

arr[flg] = swp;

}
}

int main()

int arr[100], t;

printf("banyak data : ");

scanf("%d", &t);

for(int i=0;i<t;i++){

scanf("%d", &arr[i]);

bubblesort(arr, t);

printf("bubble sort :\n");

for(int i=0;i<t;i++){

printf("%d ", arr[i]);

printf("\n");

selectionsort(arr, t);

printf("selection sort :\n");

for(int i=0;i<t;i++){

printf("%d ", arr[i]);

printf("\n");

return 0;

You might also like