Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- long int bubble(long int array[], long int length_of_array){
- int iteration, i;
- for (iteration = 0; iteration < length_of_array; iteration++){
- for (i = iteration; i < length_of_array-1; i++){
- if (array[i] < array[i+1]){
- array[i] = array[i+1] + array[i];
- array[i+1] = array[i] - array[i+1];
- array[i] = array[i] - array[i+1];
- }
- }
- }
- return 0;
- }
- int main(void){
- long int length_of_array, i, number;
- long int specificator = 0;
- while (specificator != 1){
- specificator = scanf("%ld", &length_of_array);
- }
- long int array[length_of_array];
- for (i = 0; specificator == 1 && i < length_of_array; i++){
- specificator = scanf("%ld", &number);
- array[i] = number;
- }
- if (i != length_of_array || specificator != 1)
- printf("\nbad input\n");
- else if (length_of_array != 1){
- bubble(array, length_of_array);
- }
- for (i = 0; i < length_of_array; i++){
- printf("%ld ", array[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement