Home > Back-end >  A C program
A C program

Time:09-17

According to number 10 will from small to large order in an integer array (sort () function), from the keyboard input a number, find out which number is the number of the array (find () function), if the number is not in an array, then print out the "of" no this number,

CodePudding user response:

# include
# include

Void the sort (int * a, int len)
{
Int I, j, temp.
for(i=0; I{
For (j=I + 1; j{
If (a [I] & gt; A [j])
{
Temp=a, [I].
a[i]=a[j];
A [j]=temp;
}
}
}
}

Int the find (int * a, int len, int n)
{
int i;
for (i=0; I{
If (n==a [I])
{
return i+1;
}
}
return -1;
}

Void main ()
{
[10] int a, b, I;
Printf (" please enter the number 10: \ n ");
for (i=0; I<10; I++)
{
The scanf (" % d ", & amp; A [I]);
}
Sort (a, 10);
for (i=0; I<10; I++)
{
Printf (" % d ", a [I]);
}
Printf (" \ n to enter to search: \ n ");
The scanf (" % d ", & amp; B);
Int n=find (10, a, b);
If (1==I)
{
Printf (" this number cannot be found!" );
return;
}
Printf (" % d in the first % d \ n ", b, n);
}
  • Related