</pre><h2>题目描述</h2><div class="content"><p>运动会开了n天,第n天发出金牌m枚。第一天发金牌1枚,第二天发金牌前一天的两倍加一枚,以后每天都照此办理。</p><p>开了n天,第n天发了m块金牌。你能编个简单的小程序求算m吗?</p></div><h2>输入</h2><div class="content"><p>输入一个整数n,表示运动会开的天数。</p></div><h2>输出</h2><div class="content"><p>计算对应发的奖牌数m。</p></div><h2>样例输入</h2><pre class="content"><span class="sampledata">1</span>
样例输出
1
提示
主函数与头文件已给定如下,提交时不需要包含下述主函数与头文件
/*C++*/
#include<iostream>
using namespace std;
int main()
{
int gold;
int count(int);
cin>>gold;
cout<<count(gold);
}
/*C*/
#include<stdio.h>
int main()
{
int gold;
int count(int);
scanf("%d",&gold);
printf("%d\n",count(gold));
}
解答
<span style="background-color: rgb(102, 255, 153);">#include<iostream>
using namespace std;
int main()
{
int gold;
int count(int);
cin>>gold;
cout<<count(gold);
}int count(int n)
{
int f;
if(n==1)
{
return 1;
}
else
{
f=count(n-1)*2+1;
return f;
}
}</span>