%d与%1d,%2d
#include <iostream>/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv)
{
long square(long); /*函数声明*/
long in_num,result;
printf("Input an integer:");
scanf("%d",&in_num);
result=square(in_num); /*函数调用*/
printf("\nThe square number of %d is %d",in_num,result);
return 0;
}
long square(long x) /*函数定义*/
{
long x_square; /*说明部分*/
x_square=x*x; /*执行部分*/
return x_square;
}
这个是求一个整数平方的程序,如果把%d改为%1d,那么就只能求1~9的平方,如果是%2d,那么只能求1~99的平方,这该怎么理解?
PS:%1d的情况下,如果输入10,结果是The square number of 1 = 1;%2d的情况下,如果输入100,结果是The square number of 10 = 100.