Home > Back-end >  Small white for help (about a custom function)
Small white for help (about a custom function)

Time:11-28

C language in the homework problems:
Write a program to the user to enter the five integers, procedures in the order since the childhood to print user input five integers, two functions to define and statements in the program,
The first function is the minimum value, there are three parameters, the first parameter is the one dimension array, the second parameter is the beginning of the array subscript values, the third argument to the length of the array, the second parameter is used, in the call for the minimum function, not every need from 0 subscript, namely can again when given an array in the function of the minimum range,
The second function is sorting function that requires two parameters, the first parameter is the one dimension array, the second parameter is the array length,
In the second function call the first function, c
The main function is used to handle user input and call sort function (the second) and print the results,

As shown above, I've defined a [5], I and n global variables, and then run the results for "Segmentation fault (core dumped)"
Want to ask you how great god can adjust in the case of without the use of Pointers to achieve the effect of homework required? (or is a problem in the custom function?)

CodePudding user response:

When sort function call and there is a problem, is the same as the min function;

In addition, the sort function in dealing with cross-border,

Suggested the original poster posted the code ~

CodePudding user response:

reference 1/f, confident boy reply:
sort when the function call and there is a problem, is the same as the min function;

In addition, the sort function in dealing with cross-border,

Suggested I posted the code ~

In the picture is the source code

CodePudding user response:

1, c + + have a min macro definition, the function cannot be named min
2, the min function has no return value
3, finally sort function has no return value (' sort: not all control paths return a value)
4, min function sort function call, the first parameter wrong, return min (a, n, I);
5, the main function of call sort function, the first parameter wrong, sort (a, I);
6, didn't understand n there are futile

CodePudding user response:

refer to the second floor, 6, please reply:
Quote: reference 1/f, confident boy reply:
sort when the function call and there is a problem, is the same as the min function;

In addition, the sort function in dealing with cross-border,

Suggested I posted the code ~

In the picture is the source code

That your problem is caused by such ah, only see the last sentence, I didn't see the content of the front? I mean, you can directly put forward the code also help you to change in the code, no code, only send photos, for you don't change the code,

CodePudding user response:

# include & lt; stdio.h>
Int I, n=0, a, [5].
Int min (int a [5], int n, int I)
{
For (int j=I + 1; J & lt; 5; J++)
If (a [I] & gt; A [j])
{
Int min=a [I];
a[i]=a[j];
A [j]=min;
}
Return a, [5].
}
Int the sort (int a [5], int I)
{
Int min (int a [5], int, int).
For (I=n; I & lt; 5; I++)
{
Return min (a, n, I);
}
}
Int main ()
{
Printf (" enter five integers: ");
The scanf (" % d % d % d % d % d ", & amp; A [0], & amp; A [1], & amp; A [2], & amp; A [3], & amp; A [4]);
Printf (" sorted Numbers are: ");
for (i=0; I & lt; 5; I++)
{
Printf (" % d ", sort (a, I));
}
printf("\n");
return 0;
}
Above is the original code feel quite many places are wrong,,, then n is used to control the sorting function values of the beginning
  • Related