紧急请教 返回 DOUBLE 类型的函数

色郎中 色郎中 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public double result;
public Double hehe(int aa)
{
for (int i = 1; i < aa+1; i++)
{
resutl= (902.6 + (i - 1) * 0.4);

}
return result;
}

这样个函数,当aa= 1 时,函数返回是 902.6

等于aa=2时,返回是 903,而我想要的是 903.0

该如何返回, 返回一定要是 double 类型

也就是说 为整数时,保留一位小数
...全文

相关推荐

计算机科学与技术专业综合试题.pdf

计算机科学与技术专业综合试题.pdf

筱筱笎琞

计算机科学与技术专业综合试题汇编.pdf

计算机科学与技术专业综合试题汇编.pdf

cjd13107639592

Double-Take_Backup_Implement_V5_2

Double-Take_Backup_Implement_V5_2

cheng0823

Turbo C 2.0、Borland C++库函数及用例!

字母A开头函数函数名: abort功 能: 异常终止一个进程用 法: void abort(void);程序例:#include #include int main(void){printf("Calling abort()\n");abort();return 0; /* This is never reached */}函数名: abs功 能: 求整数的绝对值用 法: int abs(int i);程序例:#include #include int main(void){int number = -1234; printf("number:%d absolute value:%d\n",number,abs(number));return 0;}函数名: absread功 能: 绝对磁盘扇区读数据用 法: int absread( int drive, int nsects, int sectno,void *buffer );程序例:/* absread example */#include #include #include #include int main(void){int i, strt, ch_out, sector;char buf[512]; printf("Insert diskette into drive A press any key\n");getch();sector = 0;if (absread(0, 1, sector, &buf) != 0){ perror("Disk problem");exit(1); }printf("Read OK\n");strt = 3;for (i=0; i<80; i++){ ch_out = buf[strt+i];putchar(ch_out); }printf("\n");return(0); }函数名: abswrite功 能: 绝对磁盘扇区写数据用 法: int abswrite( int drive, int nsects, in tsectno,

hondely

第39篇 C++17结构化绑定与optional:面试官问我“函数返回多个值怎么办”,我的回答太老套了

本文介绍了C++17中的结构化绑定和optional特性:结构化绑定允许将复合类型解构为独立变量,提升代码可读性,特别适用于pair/tuple和map遍历场景;optional则明确表达&quot;可能有值可能无值&quot;的语义,比特殊返回值更安全。两者结合可优雅处理机器人开发中的传感器数据缺失等问题。文章还分析了面试常见考点,比较了optional与指针、异常的区别,并提及optional的链式操作作为加分项。这些特性使代码意图更清晰,体现了现代C++的设计理念。

郑伟强dev
评论 9
收藏 已收藏
分享
返回顶部
色郎中
C# 111,128 成员 642,536 内容