很简单的一道题(CE)
来源:互联网 发布:java引用传参 编辑:程序博客网 时间:2024/06/11 22:02
/*
Description
有一个简单的函数数学公式,如下
Input
重复输入多组数据
输入n(1<=n<=10),输入-1程序终止。
Output
输出f(n)的结果(保留30位小数)
Sample Input
1
3
6
10
-1
*/#include<iostream>
using namespace std;
void thrity(int a,int b,int arr[]) //取小数点之后30位的函数
{
int remainder=(a%b);
for(int i=0;i<30;i++)
{
a=remainder*10;
arr[i]=(a/b);
remainder=(a%b);
}
cout<<"0.";
for(i=0;i<30;i++) //i是不是应该换成j之类另一个变量
{
cout<<arr[i];
}
cout<<endl;
}
int main()
{
void thrity(int a,int b,int arr[]);
int n,a[30];
while(cin>>n&&n!=-1)
{
int sum=0,mul=1;
for(int i=1;i<=n;i++)
{
sum+=i;
mul=mul*i;
}
if(n%2==0)
thrity(1,sum,a);
else
thrity(1,mul,a);
}
return 0;
}
using namespace std;
void thrity(int a,int b,int arr[]) //取小数点之后30位的函数
{
int remainder=(a%b);
for(int i=0;i<30;i++)
{
a=remainder*10;
arr[i]=(a/b);
remainder=(a%b);
}
cout<<"0.";
for(i=0;i<30;i++) //i是不是应该换成j之类另一个变量
{
cout<<arr[i];
}
cout<<endl;
}
int main()
{
void thrity(int a,int b,int arr[]);
int n,a[30];
while(cin>>n&&n!=-1)
{
int sum=0,mul=1;
for(int i=1;i<=n;i++)
{
sum+=i;
mul=mul*i;
}
if(n%2==0)
thrity(1,sum,a);
else
thrity(1,mul,a);
}
return 0;
}
/*
Main.cc: In function ‘void thrity(int, int, int*)’:
Main.cc:13: error: name lookup of ‘i’ changed for ISO ‘for’ scoping
Main.cc:13: note: (if you use ‘-fpermissive’ G++ will accept your code)
Main.cc:13: error: name lookup of ‘i’ changed for ISO ‘for’ scoping
Main.cc:13: note: (if you use ‘-fpermissive’ G++ will accept your code)
vc运行对的
*/
0 0
- 很简单的一道题(CE)
- 一道简单的题
- Problem C: 很简单的一道题
- 2457: 很简单的一道题
- YTU 2457: 很简单的一道题
- 一道很简单的题目
- 一道简单的笔试题
- 一道简单的多线程题
- 一道简单的洗牌题
- 一道简单的填空题
- 一道简单的笔试题
- 一道简单的Python题
- 一道简单的算法题
- 一道简单的算法题
- 递归的一道简单题
- 一道简单的递归题
- 一道简单的编程题
- 很简单却很容易做错的一道笔试题
- 代理模式和target-action模式
- Stack的三种含义
- 网页前端调试工具
- 位运算符(一):C/C++位运算符
- SQL两日期相减
- 很简单的一道题(CE)
- 深入Python学习
- 整数的加法拆分
- PLSQL Developer连接远程Oracle数据库
- Oracle EBS 创建并发请求
- sqlserver如何快速查找使用了某个字段的所有存储过程
- ocp 1Z0-051 141-175题解析
- 一定范围内特定素数和
- Oracle EBS常用表