switch语句的运用

作者:没什么大不了 | 创建时间: 2023-05-09
switch语句的运用至关重要。现在举一个简单例子进行说明。计算:s=1+1/2+1/3...1/n的值。...
switch语句的运用

操作方法

进入VC++,新建C++文件。

编写程序: #include <stdio.h> void main() { int i,n; double s=0.0; printf("请输入变量n的值:   "); scanf("%d",&n); i=1; while(i<=n) { s+=1.0/i; i++; } printf("s=%f\n",s); }

运行结果检验:

温馨提示

switch要多加练习才能熟练运用。
点击展开全文

更多推荐