很简单的一道题(CE)

/*

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;
}
 
 
/*
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)
 
 
vc运行对的
*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值