zoukankan      html  css  js  c++  java
  • C语言成长学习题(二)

    六、编写程序,在scanf函数中指定输入数据的宽度。

    1 #include <stdio.h>
    2 
    3 void main(void)
    4 {
    5     int a;
    6     scanf("a=%3d", &a);
    7     printf("a=%d
    ", a);
    8 }

    结果:

    输入      输出

    a=12     a=12

    a=1234     a=123

    12       a=(未知)

      可以在scanf函数的格式说明符前,用一个整数指定输入的最大宽度,但对实型数不可以指定宽度。

    七、编写程序,从键盘输入三个数据12、A、34,分别存放在a、b、c中。

     1 #include <stdio.h>
     2 
     3 void main(void)
     4 {
     5     int a, c;
     6     char b;
     7 
     8     printf("Enter a, b, c: ");
     9     scanf("%d%c%d", &a, &b, &c);
    10     printf("%d, %c, %d
    ", a, b, c);
    11 }

    结果:

    Enter a, b, c: 12A34

    12, A, 34

    八、编写一个使用字符输入函数getch(getche)和字符输出函数putch的程序。

     1 #include <stdio.h>
     2 #include <conio.h>
     3 
     4 void main(void)
     5 {
     6     char ch;
     7 
     8     printf("Input two character:
    ");
     9     ch = getch();                                    //或者ch = getche();
    10     putch(ch);
    11     ch = getch();
    12     putch(ch);
    13 }

    结果:

    Input two character:

    ab(使用getch()时输入的符号没有显示在屏幕上)

    Mark:

    getchar, getch, getche的区别
    函数

    是否需要回车

    是否显示在屏幕上
    getchar
    getch
    getche

     九、编写一个getch函数的应用程序。

    1 #include <stdio.h>
    2 #include <conio.h>
    3 
    4 void main(void)
    5 {
    6     printf("Let' study the C language.
    ");
    7     printf("按任意键继续!
    ");
    8     getch();
    9 }

      "clrscr()"是清屏函数。

  • 相关阅读:
    GNU make manual 翻译(九十九)
    GNU make manual 翻译( 九十五)
    Shell的 for 循环小例子
    makefile中对目录遍历的小例子
    GNU make manual 翻译(九十三)
    GNU make manual 翻译( 一百)
    GNU make manual 翻译( 九十七)
    GNU make manual 翻译( 九十八)
    mapserver4.8.3 的readme.win32的中文翻译文件
    遥控器编程
  • 原文地址:https://www.cnblogs.com/zero-jh/p/5022722.html
Copyright © 2011-2022 走看看