-
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.
-
#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.
-
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]);
First of all, because this array only has 10 data, and the subscript starts from 0 and ends at i=9. >>>More
When bubbling sorted.
for j = 0 to n - 2 >>>More
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
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
The program calculates the angle between the two needles at any time between 0:00 and 23:59. >>>More