C language bubble arrangement problem

Updated on technology 2024-05-14
3 answers
  1. Anonymous users2024-02-10

    Bubbling is to pick the smallest number from a sequence of numbers and exchange it with the first number, you have too many mistakes in this program.

    for(j=1;j<=i;j++)

    for(k=1;k<=i-j;k++)

    if(num[i]>num[i+1])

    t=num[i];

    num[i]=num[i+1];

    num[i+1]=t;

    What is the use of using j and k as circulation factors, but the changes in it have nothing to do with j and k? And your ii, which will cause confusion in reading, and too many variable references.

  2. Anonymous users2024-02-09

    #include

    int main(void)

    int num[100],i=0,n,j,k,t,ii;

    char key;

    printf("Please enter n digits, a negative number indicates that the input is complete");

    do ++i;

    printf("%d. -",i);

    scanf("%d",&n);

    fflush(stdin);

    num[i]=n;

    while(num[i]>0);

    i--;//

    for(j=1;j<=i;j++)

    for(k=1;k<=i-j;k++)

    if(num[k]>num[k+1]) //t=num[k];

    num[k]=num[k+1];

    num[k+1]=t;

    for(ii=i,i=2;i<=ii;i++)printf("%d ",num[i]);In terms of procedure.

  3. Anonymous users2024-02-08

    if(num[i]>num[i+1])

    t=num[i];

    num[i]=num[i+1];

    num[i+1]=t;

    where i should be replaced by k, i.e., read as follows:

    if(num[k]>num[k+1])

    t=num[k];

    num[k]=num[k+1];

    num[k+1]=t;

    In addition, it is proposed that the last part of the procedure be changed to the following form:

    for(ii=i,i=2;i<=ii;i++)printf("%d ",num[i]);

Related questions
8 answers2024-05-14

First of all, because this array only has 10 data, and the subscript starts from 0 and ends at i=9. >>>More

8 answers2024-05-14

When bubbling sorted.

for j = 0 to n - 2 >>>More

6 answers2024-05-14

This is the classic all-permutation algorithm. m and k represent the range of elements to be fully arranged, i.e., the index of the two endpoints, m is the beginning index, and k is the end endpoint index. >>>More

9 answers2024-05-14

Scope. You static char *chh;

static char *ch1;Although the address pointed to by the two pointers does not change, have you ever wondered whether the memory address they point to has been released, char chc[10]; It's local, the function is out, the lifecycle is over, and you're trying to access it with a pointer in void times(). >>>More

14 answers2024-05-14

The program calculates the angle between the two needles at any time between 0:00 and 23:59. >>>More