This C code implements the bubble sort algorithm to sort three integers provided by the user in ascending order. It then prints the sorted numbers in the format 'a->b->c'.

#include<stdio.h>
int main(){
    int a[3],temp;
    for(int i=0;i<3;i++){
        scanf('%d',&a[i]);
    }
    for(int i=0;i<2;i++){
        for(int j=i;j<3;j++){
            if(a[j]>a[j+1]){
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
        }
    }
    for(int i=0;i<2;i++){
        printf('%d',a[i]);
        printf('->');
    }
    printf('%d',a[2]);
    return 0;
}

Example Input:

5 2 7

Output:

2->5->7

C Programming: Bubble Sort Algorithm for Sorting Integers

原文地址: https://www.cveoy.top/t/topic/mCHK 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录