面试题12

考虑大数问题,下面的代码只是对输入做了判断,但是没有考虑大数溢出的问题。

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

#include "stdafx.h"
/*
程序特点:
1.全面
	1.考虑到很多情况,比如,此题如果只考虑大于0的情形,则不可以
	2.错误处理
2.高效
*/
#include <math.h>
#include <stdio.h>
using namespace std;
void PrintN(int n)
{
	if (n < 1)
	{
		printf("错误,请输入大于1的数\n");
	}
	else
	{
		int max_num = pow(10.0 ,n);
		for (int i = 1; i < max_num; i++)
		{
			printf("%d\n",i);
		}
	}
}
int _tmain(int argc, _TCHAR* argv[])
{
	PrintN(3);
	return 0;
}


posted @ 2018-04-04 11:56  开往春天的拖拉机  阅读(67)  评论(0编辑  收藏  举报