scanf 之 %2s 与 %2d

在scanf语句中%*s,在c语言中的说明是该处的*表示忽略该处的变量输入。

还是看一下下面的程序说明吧:

#include<stdio.h>
int main()
{
    int a,b;
    scanf("%2d%*2s%d",&a,&b);
    printf("\na=%d,b=%d\n",a,b);
    return 0;
}

运行结果:

输入:12345678

输出:a=12,b=5678

输入:123456

输出:a=12,b=56

那么,就说明在该处,%*2s表示忽略2个字符的输入。注意这里要是输入是小于4位数的数字的话,程序是不能继续运行的,需要输入大于4位的数字,这个由scanf分析可以得到。

时间: 2024-10-23 02:13:45

scanf 之 %2s 与 %2d的相关文章

scanf,fscanf,sscanf的区别----整理

转自原文 scanf,fscanf,sscanf的区别----整理 scanf 从控制台输入 fscanf 从文件输入 sscanf 从指定字符串输入 1.例:使用scanf函数输入数据. #include<stdio.h> int main() { int a,b,c; printf("输入 a, b, c\n"); scanf("%d,%d,%d", &a, &b, &c); printf("a = %d b = %

ACM学习历程——UVA 127 &quot;Accordian&quot; Patience(栈;模拟)

Description  ``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patience, the rules for which are as follows: Deal cards one by one in a row from left to right, not overlapping. Whenever the card matches its immediate n

Uva 127 poj 1214 `Accordian&#39;&#39; Patience

 ``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patience, the rules for which are as follows: Deal cards one by one in a row from left to right, not overlapping. Whenever the card matches its immediate neighbour on

&quot;Accordian&quot; Patience UVA 127 (”手风琴“牌游戏)

"Accordian" Patience From:UVA, 127 Submit Time Limit: 3000 MS You are to simulate the playing of games of ``Accordian'' patience, the rules for which are as follows: Deal cards one by one in a row from left to right, not overlapping. Whenever th

mysql数据类型和用法

``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patience, the rules for which are as follows: Deal cards one by one in a row from left to right, not overlapping. Whenever the card matches its immediate neighbour on t

ACM学习历程——UVA127 &quot;Accordian&quot; Patience(栈, 链表)

Description  ``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patience, the rules for which are as follows: Deal cards one by one in a row from left to right, not overlapping. Whenever the card matches its immediate n

``Accordian&amp;#39;&amp;#39; Patience

``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patience, the rules for which are as follows: Deal cards one by one in a row from left to right, not overlapping. Whenever the card matches its immediate neighbour on t

UVa OJ 127 - &quot;Accordian&quot; Patience (“手风琴”纸牌)

UVa OJ 127 - "Accordian" Patience ("手风琴"纸牌) Time limit: 3.000 seconds 限时:3.000秒 Problem 问题 You are to simulate the playing of games of "Accordian" patience, the rules for which are as follows: 模拟玩一个"手风琴"纸牌游戏,规则如下: D

编程题:用递归调用实现,求N!(!阶乘)。

#include<stdio.h> long fac(int n) { if(n==1) return 1L;             /*"1L"为长整型常量*/ else return n*fac(n-1); } void main() {int m; scanf("%d",&m); printf("%2d!=%d\n",m,fac(m)); } 算法解析: 运行结果: 编程题:用递归调用实现,求N!(!阶乘).,布布扣,