习题 102:等差数列☆

传说中数学王子高斯小时候利用规律很快的将1+2+……+100算出来
现在有一个类似的问题,就是要求1+2+……+10^n.
你能很快地算出来么?


输入:
多个case,每个case只有一个自然数 n (0<=n<=10000)


输出:
上面那个问题的结果


样例输入:
1
2


样例输出:
55
5050


其它信息:
题目提供:ailyanlu
Contest 13 竞赛题目


难度:For Beginner[/mytable]






site:http://www.yzfy.org/dis/listpost.php?tid=741&extra=page%3D1
规律:
输入       输出
0           1
1           55
2           5050
3           500500
---         ------
TIPS: 

直接计算:
头文件:math.h/cmath(C++中)

double pow( double x, double y ); //x的y次方

// 102.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdio.h"

int main(int argc, char* argv[])
{
	int i, n;
	while( scanf("%d", &n) != EOF )
	{
		if( n == 0) { printf("1\n"); continue;}
		printf("5");
		for (i=0; i<n-1; i++) printf("0");
		printf("5");
		for (i=0; i<n-1; i++) printf("0");
		printf("\n");
	}
	return 0;
}



你可能感兴趣的:(算法,vc++6.0)