Redian新闻
>
please help the following (in C or C+)
avatar
please help the following (in C or C+)# JobHunting - 待字闺中
n*c
1
I was asked the following?
Complete the body of the following function:
/** Return the index in array data of the element closest to or
equal to value. The array data has exactly data_count
elements. */
size_t find_nearest (int value, const int* data, size_t data_count);
Any quick code? thanks a lot
avatar
l*n
2
为什么这种code也来求啊?是作业么?
就是个简单循环一遍的事情,都不涉及到多指针,自己还搞不定的话,以后能干活儿么?

【在 n*c 的大作中提到】
: I was asked the following?
: Complete the body of the following function:
: /** Return the index in array data of the element closest to or
: equal to value. The array data has exactly data_count
: elements. */
: size_t find_nearest (int value, const int* data, size_t data_count);
: Any quick code? thanks a lot

avatar
n*c
3
I'm not computer guy, try to get similar C/C+ code, any suggestion is
appreciated. Thanks.
avatar
n*c
4
Can anyone show me a quick code?
many thanks.
avatar
n*c
5
do i need 指针? or just a array?
many thanks.
avatar
n*c
6
please help me with a quick code, i need online submit.
thanks.
avatar
A*i
7
size_t find_nearest(int value, const, int * data, size_t data_count) {
size_t res = 0;
int tmp1 = 0;
int tmp2 = value;

if (0 == data_count)
return data_count;

for (size_t i = 0; i < data_count; i++) {
tmp1 = value >= data[i]? (value - data[i]):(data[i] - value);
if (tmp1 < tmp2){
tmp2 = tmp1;
res = i;
}
}

return res;
}
老朽多年不写C和C++了,也不知道对不,nodejs害人不浅啊
avatar
f*2
8
献丑了,不知道理解对不,请lz自己调试一下
int fabs(int var1, int var2);
size_t find_nearest(int value, const int* data, size_t data_count);
{
int index,indexValue, temp;
temp = fabs(value, data[0]);
indexValue = 0;
for(index=0; index < data_count; index++)
{
if(temp > fabs(value, data[index]))
indexValue = index;
}
return (size_t)indexValue;
}
int fabs(int var1, int var2)
{
retrun var1 >= var2? (var1-var2): -(var1-var2);
}
avatar
n*c
9
this is great, i'm trying understanding your code.
thanks for your kindness.
avatar
n*c
10
appreciated Avenssi (蛋疼帝) and fit2012 (fit2012).
Thanks so much.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。