标签:void return oid lse turn i++ amp 编写 count
/*革启博客,革启网,袁欢,袁欢的博客,袁欢博客 版本:vs2019社区版 功能;编写一个函数求1+1/2+1/3+...+1/n的值 */ #include<stdio.h> float count(int n) { int i; float sum; if (n <= 0) { printf("非法数据!\n"); return -1; } else { sum = 0; for(i = 1; i <= n; i++) { sum = sum + 1 / i; } return sum; } } void main() { int n; float sum; printf("请输入n的值:\n"); scanf_s("%d", &n); sum = count(n); printf("n=%d sum=%f\n", n, sum); }
标签:void return oid lse turn i++ amp 编写 count
原文地址:https://www.cnblogs.com/qq1480040000/p/13376575.html