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()"是清屏函数。

  • 相关阅读:
    C/C++ 编写一个通用的Makefile 来编译.c .cpp 或混编
    C/C++ 定义接口文件格式
    MySql存储过程例子1
    项目所遇问题
    linux下编译C++程序无法链接Mysql的问题
    linux 同步时间 调试core内核
    CentOS安装与更新git
    03 js基本数据类型、 js运算符1
    02 js运行原理 、js开发工具介绍 、js程序入门、 js基本语法
    01 js基本介绍
  • 原文地址:https://www.cnblogs.com/zero-jh/p/5022722.html
Copyright © 2011-2022 走看看