国民生产总值翻番 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description
已知今年的国民生产总值(随意假定一个合理数值),假设我国国民经济增速按6%计算,请编程计算出至少多少年才能翻一番。要求输出求得的年数及刚好翻番这年的国民生产总值。并计算n年之后我国国民经济是今年的多少倍。 Input
输入一个正整数(n年) Output
刚好翻一番的是第几年。 第n年我国国民经济是今年的多少倍(精确到百分位)。 Sample Input
8 Sample Output
12 1.59 Hint
Source 本文旨在为非计算机专业同学提供帮助
#include <stdio.h>
int main()
{
double n,s,q,d=1.0;
int flag=0;
int p,i;
scanf("%lf",&n);
s=1.06*1;
for(i=2;i<=1000;i++)
{
s=s*1.06;
if((s/d>=2)&&flag==0)
{p=i;flag=1;}
if(i==n)
q=s/1;
}
printf("%d\n%.2lf",p,q);
return 0;
}