| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2377 人关注过本帖
标题:%d与%1d,%2d
只看楼主 加入收藏
eagle鹏
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-2-25
收藏
 问题点数:0 回复次数:1 
%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.
搜索更多相关主题的帖子: include system number return result 
2017-02-25 18:14
云团
Rank: 2
等 级:论坛游民
帖 子:36
专家分:41
注 册:2017-1-9
收藏
得分:0 
%nd  n是输入数字的长度,  要是n为2,就是只能读取两位数
 要是n为3,就是只能读取三位数
2017-02-25 20:30
快速回复:%d与%1d,%2d
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017303 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved