/*
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运行对的
*/