bin_search return an array with 15 elements in C++
up vote
-4
down vote
favorite
I would like to create an array i_array
with 15 elements and rate every element with formula
a = sin((Pi * (i - 7)) / 15)
and return it.
#include <cmath>
#include <cstddef>
#include <iostream>
void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}
void modBinSearch(double arr, double start, double end){
if (start > end){
return -1;
}
const int mitte = start +((end-start)/2);
if(arr[mitte] == 0.0){
return mitte;
}
else if(arr[mitte] > 0.0){
return modBinSearch(arr, start, mitte-1);
}
return modBinSearch(arr, mitte+1,end);
}
int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
int arr = sinuss(i_array);
int n = sizeof(arr)/sizeof(arr[0]);
int result = modBinSearch(arr, 0, n-1);
return 0;
}
I have no idea. I don't know what my error is.
I am new in C++, because it I have a lot of problem with it:(
In my function sinuss() I should return rated elements as array and in function modBinSearch() I should return the least element who not smaller as 0.0 is. But my programm is wrong :(
c++
|
show 2 more comments
up vote
-4
down vote
favorite
I would like to create an array i_array
with 15 elements and rate every element with formula
a = sin((Pi * (i - 7)) / 15)
and return it.
#include <cmath>
#include <cstddef>
#include <iostream>
void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}
void modBinSearch(double arr, double start, double end){
if (start > end){
return -1;
}
const int mitte = start +((end-start)/2);
if(arr[mitte] == 0.0){
return mitte;
}
else if(arr[mitte] > 0.0){
return modBinSearch(arr, start, mitte-1);
}
return modBinSearch(arr, mitte+1,end);
}
int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
int arr = sinuss(i_array);
int n = sizeof(arr)/sizeof(arr[0]);
int result = modBinSearch(arr, 0, n-1);
return 0;
}
I have no idea. I don't know what my error is.
I am new in C++, because it I have a lot of problem with it:(
In my function sinuss() I should return rated elements as array and in function modBinSearch() I should return the least element who not smaller as 0.0 is. But my programm is wrong :(
c++
1
This should not be tagged with c#
– George Helyar
Nov 11 at 10:23
Where is the memory declared for the returned data? You can't return an array to a pointer from a function. A function variables a placed on the execution stack. When you return from a function the stack variables are disposed and no longer exist. So you have to declare the memory for the array in the main so the data is copied on the return from the method before the data is disposed.
– jdweng
Nov 11 at 10:33
That sould not be tagged with C either.
– Swordfish
Nov 11 at 10:52
thank you. I am new in programming.:( So I changed my code. Do you mean so?
– KG. Boys
Nov 11 at 10:54
there is no point in#include
ing<cmath>
and<math.h>
– Swordfish
Nov 11 at 10:56
|
show 2 more comments
up vote
-4
down vote
favorite
up vote
-4
down vote
favorite
I would like to create an array i_array
with 15 elements and rate every element with formula
a = sin((Pi * (i - 7)) / 15)
and return it.
#include <cmath>
#include <cstddef>
#include <iostream>
void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}
void modBinSearch(double arr, double start, double end){
if (start > end){
return -1;
}
const int mitte = start +((end-start)/2);
if(arr[mitte] == 0.0){
return mitte;
}
else if(arr[mitte] > 0.0){
return modBinSearch(arr, start, mitte-1);
}
return modBinSearch(arr, mitte+1,end);
}
int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
int arr = sinuss(i_array);
int n = sizeof(arr)/sizeof(arr[0]);
int result = modBinSearch(arr, 0, n-1);
return 0;
}
I have no idea. I don't know what my error is.
I am new in C++, because it I have a lot of problem with it:(
In my function sinuss() I should return rated elements as array and in function modBinSearch() I should return the least element who not smaller as 0.0 is. But my programm is wrong :(
c++
I would like to create an array i_array
with 15 elements and rate every element with formula
a = sin((Pi * (i - 7)) / 15)
and return it.
#include <cmath>
#include <cstddef>
#include <iostream>
void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}
void modBinSearch(double arr, double start, double end){
if (start > end){
return -1;
}
const int mitte = start +((end-start)/2);
if(arr[mitte] == 0.0){
return mitte;
}
else if(arr[mitte] > 0.0){
return modBinSearch(arr, start, mitte-1);
}
return modBinSearch(arr, mitte+1,end);
}
int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
int arr = sinuss(i_array);
int n = sizeof(arr)/sizeof(arr[0]);
int result = modBinSearch(arr, 0, n-1);
return 0;
}
I have no idea. I don't know what my error is.
I am new in C++, because it I have a lot of problem with it:(
In my function sinuss() I should return rated elements as array and in function modBinSearch() I should return the least element who not smaller as 0.0 is. But my programm is wrong :(
c++
c++
edited Nov 11 at 21:11
asked Nov 11 at 10:14
KG. Boys
136
136
1
This should not be tagged with c#
– George Helyar
Nov 11 at 10:23
Where is the memory declared for the returned data? You can't return an array to a pointer from a function. A function variables a placed on the execution stack. When you return from a function the stack variables are disposed and no longer exist. So you have to declare the memory for the array in the main so the data is copied on the return from the method before the data is disposed.
– jdweng
Nov 11 at 10:33
That sould not be tagged with C either.
– Swordfish
Nov 11 at 10:52
thank you. I am new in programming.:( So I changed my code. Do you mean so?
– KG. Boys
Nov 11 at 10:54
there is no point in#include
ing<cmath>
and<math.h>
– Swordfish
Nov 11 at 10:56
|
show 2 more comments
1
This should not be tagged with c#
– George Helyar
Nov 11 at 10:23
Where is the memory declared for the returned data? You can't return an array to a pointer from a function. A function variables a placed on the execution stack. When you return from a function the stack variables are disposed and no longer exist. So you have to declare the memory for the array in the main so the data is copied on the return from the method before the data is disposed.
– jdweng
Nov 11 at 10:33
That sould not be tagged with C either.
– Swordfish
Nov 11 at 10:52
thank you. I am new in programming.:( So I changed my code. Do you mean so?
– KG. Boys
Nov 11 at 10:54
there is no point in#include
ing<cmath>
and<math.h>
– Swordfish
Nov 11 at 10:56
1
1
This should not be tagged with c#
– George Helyar
Nov 11 at 10:23
This should not be tagged with c#
– George Helyar
Nov 11 at 10:23
Where is the memory declared for the returned data? You can't return an array to a pointer from a function. A function variables a placed on the execution stack. When you return from a function the stack variables are disposed and no longer exist. So you have to declare the memory for the array in the main so the data is copied on the return from the method before the data is disposed.
– jdweng
Nov 11 at 10:33
Where is the memory declared for the returned data? You can't return an array to a pointer from a function. A function variables a placed on the execution stack. When you return from a function the stack variables are disposed and no longer exist. So you have to declare the memory for the array in the main so the data is copied on the return from the method before the data is disposed.
– jdweng
Nov 11 at 10:33
That sould not be tagged with C either.
– Swordfish
Nov 11 at 10:52
That sould not be tagged with C either.
– Swordfish
Nov 11 at 10:52
thank you. I am new in programming.:( So I changed my code. Do you mean so?
– KG. Boys
Nov 11 at 10:54
thank you. I am new in programming.:( So I changed my code. Do you mean so?
– KG. Boys
Nov 11 at 10:54
there is no point in
#include
ing <cmath>
and <math.h>
– Swordfish
Nov 11 at 10:56
there is no point in
#include
ing <cmath>
and <math.h>
– Swordfish
Nov 11 at 10:56
|
show 2 more comments
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
Define a type of what you desire. Suggesting a std::array<double,15>
. It makes coding what you want more natural.
#include <array>
#include <iostream>
#include <cmath>
using namespace std;
using ArrOf15Dbl = array<double, 15>;
ArrOf15Dbl sinuss() {
ArrOf15Dbl i_array;
for (int i = 0; i < 15; ++i) {
i_array[i] = sin((M_PI * (i - 7)) / 15);
cout << i_array[i] << ' ';
}
cout << 'n';
return i_array;
}
int main() {
ArrOf15Dbl x = sinuss();
for (auto i : x) {
cout << i << ' ';
}
cout << 'n';
}
But returning arrays from a function is not possible with C++98/03. So one solution is to allocate the needed memory dynamically, but don't forget to release it later!
#include <cmath>
#include <cstddef>
#include <iostream>
int const kArrSiz = 15;
// OBS: caller assumes ownership of array pointer!
// Must be deleted with "delete foobar;"
double* sinuss() {
double* i_array = new double[kArrSiz];
for (int i = 0; i < kArrSiz; ++i) {
i_array[i] = std::sin((M_PI * (i - 7)) / kArrSiz);
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return i_array;
}
int main() {
double* x = sinuss();
for (int i = 0; i < kArrSiz; ++i) {
std::cout << x[i] << ' ';
}
std::cout << 'n';
delete x;
return EXIT_SUCCESS;
}
But with a change of interface to your function, it can be made safer by requiring the caller to allocate the array and your function instead fills it with your required values.
void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}
int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return EXIT_SUCCESS;
}
mmh, I didn't understand your code. If I copy and pasta,there are a lot of errors
– KG. Boys
Nov 11 at 15:54
@KG.Boys What compiler are you running and with which version of C++ are you trying to use?
– Bo R
Nov 11 at 16:59
I use GCC, and gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
– KG. Boys
Nov 11 at 18:32
So, thank you. The second one works , I got in output all elements, but I need it as array, because I must write my second function , so that I can use this array in my second function. :(
– KG. Boys
Nov 11 at 18:43
@KG.Boys There is partial C++11 support in gcc 4.8.2. You might want to try and add-std=gnu++0x
to the compile command.
– Bo R
Nov 11 at 19:13
|
show 3 more comments
up vote
2
down vote
There are usually better ways to write loops that use a sequence of floating-point values, such as using an integer for loop control and calculating the floating-point value from the integer in each iteration. (Alternatively, you can use a floating-point object for loop control but take care to use only integer values for the loop expressions.)
thank you Ichanged my code.Do you mean so?
– KG. Boys
Nov 11 at 11:15
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Define a type of what you desire. Suggesting a std::array<double,15>
. It makes coding what you want more natural.
#include <array>
#include <iostream>
#include <cmath>
using namespace std;
using ArrOf15Dbl = array<double, 15>;
ArrOf15Dbl sinuss() {
ArrOf15Dbl i_array;
for (int i = 0; i < 15; ++i) {
i_array[i] = sin((M_PI * (i - 7)) / 15);
cout << i_array[i] << ' ';
}
cout << 'n';
return i_array;
}
int main() {
ArrOf15Dbl x = sinuss();
for (auto i : x) {
cout << i << ' ';
}
cout << 'n';
}
But returning arrays from a function is not possible with C++98/03. So one solution is to allocate the needed memory dynamically, but don't forget to release it later!
#include <cmath>
#include <cstddef>
#include <iostream>
int const kArrSiz = 15;
// OBS: caller assumes ownership of array pointer!
// Must be deleted with "delete foobar;"
double* sinuss() {
double* i_array = new double[kArrSiz];
for (int i = 0; i < kArrSiz; ++i) {
i_array[i] = std::sin((M_PI * (i - 7)) / kArrSiz);
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return i_array;
}
int main() {
double* x = sinuss();
for (int i = 0; i < kArrSiz; ++i) {
std::cout << x[i] << ' ';
}
std::cout << 'n';
delete x;
return EXIT_SUCCESS;
}
But with a change of interface to your function, it can be made safer by requiring the caller to allocate the array and your function instead fills it with your required values.
void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}
int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return EXIT_SUCCESS;
}
mmh, I didn't understand your code. If I copy and pasta,there are a lot of errors
– KG. Boys
Nov 11 at 15:54
@KG.Boys What compiler are you running and with which version of C++ are you trying to use?
– Bo R
Nov 11 at 16:59
I use GCC, and gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
– KG. Boys
Nov 11 at 18:32
So, thank you. The second one works , I got in output all elements, but I need it as array, because I must write my second function , so that I can use this array in my second function. :(
– KG. Boys
Nov 11 at 18:43
@KG.Boys There is partial C++11 support in gcc 4.8.2. You might want to try and add-std=gnu++0x
to the compile command.
– Bo R
Nov 11 at 19:13
|
show 3 more comments
up vote
0
down vote
accepted
Define a type of what you desire. Suggesting a std::array<double,15>
. It makes coding what you want more natural.
#include <array>
#include <iostream>
#include <cmath>
using namespace std;
using ArrOf15Dbl = array<double, 15>;
ArrOf15Dbl sinuss() {
ArrOf15Dbl i_array;
for (int i = 0; i < 15; ++i) {
i_array[i] = sin((M_PI * (i - 7)) / 15);
cout << i_array[i] << ' ';
}
cout << 'n';
return i_array;
}
int main() {
ArrOf15Dbl x = sinuss();
for (auto i : x) {
cout << i << ' ';
}
cout << 'n';
}
But returning arrays from a function is not possible with C++98/03. So one solution is to allocate the needed memory dynamically, but don't forget to release it later!
#include <cmath>
#include <cstddef>
#include <iostream>
int const kArrSiz = 15;
// OBS: caller assumes ownership of array pointer!
// Must be deleted with "delete foobar;"
double* sinuss() {
double* i_array = new double[kArrSiz];
for (int i = 0; i < kArrSiz; ++i) {
i_array[i] = std::sin((M_PI * (i - 7)) / kArrSiz);
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return i_array;
}
int main() {
double* x = sinuss();
for (int i = 0; i < kArrSiz; ++i) {
std::cout << x[i] << ' ';
}
std::cout << 'n';
delete x;
return EXIT_SUCCESS;
}
But with a change of interface to your function, it can be made safer by requiring the caller to allocate the array and your function instead fills it with your required values.
void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}
int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return EXIT_SUCCESS;
}
mmh, I didn't understand your code. If I copy and pasta,there are a lot of errors
– KG. Boys
Nov 11 at 15:54
@KG.Boys What compiler are you running and with which version of C++ are you trying to use?
– Bo R
Nov 11 at 16:59
I use GCC, and gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
– KG. Boys
Nov 11 at 18:32
So, thank you. The second one works , I got in output all elements, but I need it as array, because I must write my second function , so that I can use this array in my second function. :(
– KG. Boys
Nov 11 at 18:43
@KG.Boys There is partial C++11 support in gcc 4.8.2. You might want to try and add-std=gnu++0x
to the compile command.
– Bo R
Nov 11 at 19:13
|
show 3 more comments
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Define a type of what you desire. Suggesting a std::array<double,15>
. It makes coding what you want more natural.
#include <array>
#include <iostream>
#include <cmath>
using namespace std;
using ArrOf15Dbl = array<double, 15>;
ArrOf15Dbl sinuss() {
ArrOf15Dbl i_array;
for (int i = 0; i < 15; ++i) {
i_array[i] = sin((M_PI * (i - 7)) / 15);
cout << i_array[i] << ' ';
}
cout << 'n';
return i_array;
}
int main() {
ArrOf15Dbl x = sinuss();
for (auto i : x) {
cout << i << ' ';
}
cout << 'n';
}
But returning arrays from a function is not possible with C++98/03. So one solution is to allocate the needed memory dynamically, but don't forget to release it later!
#include <cmath>
#include <cstddef>
#include <iostream>
int const kArrSiz = 15;
// OBS: caller assumes ownership of array pointer!
// Must be deleted with "delete foobar;"
double* sinuss() {
double* i_array = new double[kArrSiz];
for (int i = 0; i < kArrSiz; ++i) {
i_array[i] = std::sin((M_PI * (i - 7)) / kArrSiz);
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return i_array;
}
int main() {
double* x = sinuss();
for (int i = 0; i < kArrSiz; ++i) {
std::cout << x[i] << ' ';
}
std::cout << 'n';
delete x;
return EXIT_SUCCESS;
}
But with a change of interface to your function, it can be made safer by requiring the caller to allocate the array and your function instead fills it with your required values.
void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}
int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return EXIT_SUCCESS;
}
Define a type of what you desire. Suggesting a std::array<double,15>
. It makes coding what you want more natural.
#include <array>
#include <iostream>
#include <cmath>
using namespace std;
using ArrOf15Dbl = array<double, 15>;
ArrOf15Dbl sinuss() {
ArrOf15Dbl i_array;
for (int i = 0; i < 15; ++i) {
i_array[i] = sin((M_PI * (i - 7)) / 15);
cout << i_array[i] << ' ';
}
cout << 'n';
return i_array;
}
int main() {
ArrOf15Dbl x = sinuss();
for (auto i : x) {
cout << i << ' ';
}
cout << 'n';
}
But returning arrays from a function is not possible with C++98/03. So one solution is to allocate the needed memory dynamically, but don't forget to release it later!
#include <cmath>
#include <cstddef>
#include <iostream>
int const kArrSiz = 15;
// OBS: caller assumes ownership of array pointer!
// Must be deleted with "delete foobar;"
double* sinuss() {
double* i_array = new double[kArrSiz];
for (int i = 0; i < kArrSiz; ++i) {
i_array[i] = std::sin((M_PI * (i - 7)) / kArrSiz);
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return i_array;
}
int main() {
double* x = sinuss();
for (int i = 0; i < kArrSiz; ++i) {
std::cout << x[i] << ' ';
}
std::cout << 'n';
delete x;
return EXIT_SUCCESS;
}
But with a change of interface to your function, it can be made safer by requiring the caller to allocate the array and your function instead fills it with your required values.
void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}
int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return EXIT_SUCCESS;
}
edited Nov 11 at 17:32
answered Nov 11 at 14:00
Bo R
612110
612110
mmh, I didn't understand your code. If I copy and pasta,there are a lot of errors
– KG. Boys
Nov 11 at 15:54
@KG.Boys What compiler are you running and with which version of C++ are you trying to use?
– Bo R
Nov 11 at 16:59
I use GCC, and gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
– KG. Boys
Nov 11 at 18:32
So, thank you. The second one works , I got in output all elements, but I need it as array, because I must write my second function , so that I can use this array in my second function. :(
– KG. Boys
Nov 11 at 18:43
@KG.Boys There is partial C++11 support in gcc 4.8.2. You might want to try and add-std=gnu++0x
to the compile command.
– Bo R
Nov 11 at 19:13
|
show 3 more comments
mmh, I didn't understand your code. If I copy and pasta,there are a lot of errors
– KG. Boys
Nov 11 at 15:54
@KG.Boys What compiler are you running and with which version of C++ are you trying to use?
– Bo R
Nov 11 at 16:59
I use GCC, and gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
– KG. Boys
Nov 11 at 18:32
So, thank you. The second one works , I got in output all elements, but I need it as array, because I must write my second function , so that I can use this array in my second function. :(
– KG. Boys
Nov 11 at 18:43
@KG.Boys There is partial C++11 support in gcc 4.8.2. You might want to try and add-std=gnu++0x
to the compile command.
– Bo R
Nov 11 at 19:13
mmh, I didn't understand your code. If I copy and pasta,there are a lot of errors
– KG. Boys
Nov 11 at 15:54
mmh, I didn't understand your code. If I copy and pasta,there are a lot of errors
– KG. Boys
Nov 11 at 15:54
@KG.Boys What compiler are you running and with which version of C++ are you trying to use?
– Bo R
Nov 11 at 16:59
@KG.Boys What compiler are you running and with which version of C++ are you trying to use?
– Bo R
Nov 11 at 16:59
I use GCC, and gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
– KG. Boys
Nov 11 at 18:32
I use GCC, and gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
– KG. Boys
Nov 11 at 18:32
So, thank you. The second one works , I got in output all elements, but I need it as array, because I must write my second function , so that I can use this array in my second function. :(
– KG. Boys
Nov 11 at 18:43
So, thank you. The second one works , I got in output all elements, but I need it as array, because I must write my second function , so that I can use this array in my second function. :(
– KG. Boys
Nov 11 at 18:43
@KG.Boys There is partial C++11 support in gcc 4.8.2. You might want to try and add
-std=gnu++0x
to the compile command.– Bo R
Nov 11 at 19:13
@KG.Boys There is partial C++11 support in gcc 4.8.2. You might want to try and add
-std=gnu++0x
to the compile command.– Bo R
Nov 11 at 19:13
|
show 3 more comments
up vote
2
down vote
There are usually better ways to write loops that use a sequence of floating-point values, such as using an integer for loop control and calculating the floating-point value from the integer in each iteration. (Alternatively, you can use a floating-point object for loop control but take care to use only integer values for the loop expressions.)
thank you Ichanged my code.Do you mean so?
– KG. Boys
Nov 11 at 11:15
add a comment |
up vote
2
down vote
There are usually better ways to write loops that use a sequence of floating-point values, such as using an integer for loop control and calculating the floating-point value from the integer in each iteration. (Alternatively, you can use a floating-point object for loop control but take care to use only integer values for the loop expressions.)
thank you Ichanged my code.Do you mean so?
– KG. Boys
Nov 11 at 11:15
add a comment |
up vote
2
down vote
up vote
2
down vote
There are usually better ways to write loops that use a sequence of floating-point values, such as using an integer for loop control and calculating the floating-point value from the integer in each iteration. (Alternatively, you can use a floating-point object for loop control but take care to use only integer values for the loop expressions.)
There are usually better ways to write loops that use a sequence of floating-point values, such as using an integer for loop control and calculating the floating-point value from the integer in each iteration. (Alternatively, you can use a floating-point object for loop control but take care to use only integer values for the loop expressions.)
answered Nov 11 at 10:23
Md. Mokammal Hossen Farnan
577320
577320
thank you Ichanged my code.Do you mean so?
– KG. Boys
Nov 11 at 11:15
add a comment |
thank you Ichanged my code.Do you mean so?
– KG. Boys
Nov 11 at 11:15
thank you Ichanged my code.Do you mean so?
– KG. Boys
Nov 11 at 11:15
thank you Ichanged my code.Do you mean so?
– KG. Boys
Nov 11 at 11:15
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247709%2fbin-search-return-an-array-with-15-elements-in-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
This should not be tagged with c#
– George Helyar
Nov 11 at 10:23
Where is the memory declared for the returned data? You can't return an array to a pointer from a function. A function variables a placed on the execution stack. When you return from a function the stack variables are disposed and no longer exist. So you have to declare the memory for the array in the main so the data is copied on the return from the method before the data is disposed.
– jdweng
Nov 11 at 10:33
That sould not be tagged with C either.
– Swordfish
Nov 11 at 10:52
thank you. I am new in programming.:( So I changed my code. Do you mean so?
– KG. Boys
Nov 11 at 10:54
there is no point in
#include
ing<cmath>
and<math.h>
– Swordfish
Nov 11 at 10:56