Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.0 kB
1
Indexable
Never
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int *bubble(int a[],int count);

int main(void)
{
    int Stu_ID = 70357001;
    printf("Student ID: %d\n\n",Stu_ID);

//  Question Q1(a)

    printf("Q1(a)\n\n");
    int a[] = {6,5,4,3,2,1};
    int count = sizeof(a)/sizeof(a[0]);

    printf("The input sequence is: [ ");
    for (int i=0;i<count;i++)
    {
        printf("%d ",a[i]);
    }
    printf("]\n\n");

    int *ptr;
    ptr = bubble(a,count);

    printf("The sorted sequence is: [ ");
    for (int i=0;i<count;i++)
    {
        printf("%d ",*(ptr +i));
    }
    printf("]\n");
    return 0;
}

int *bubble(int a[],int count)
{
    int temp;

    for (int k=0;k<(count-1);k++)
    {
        for (int l=0;l < (count - 1 - k);l++)
        {
            if(a[l] > a[l+1])
            {
                temp = a[l];
                a[l] = a[l+1];
                a[l+1] = temp;
            }
        }

    }
    return (a);
}