年年有"余"

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1857|回复: 1

C语言基本输入输出练习

[复制链接]
  • TA的每日心情
    奋斗
    2022-12-13 21:26
  • 签到天数: 371 天

    [LV.9]以坛为家II

    发表于 2014-2-20 22:58:47 | 显示全部楼层 |阅读模式
    代码:
    1. #include <stdio.h>
    2. int main() {
    3.    
    4.                 int a = 0;
    5.                 int b = 0;
    6.                 int c = 0;
    7.    
    8.                 printf("Please input the first number:");  //提示语
    9.                 scanf("%d", &a);   //调用系统函数“scanf()”,输入整数,通过取变量地址将接收值返回        
    10.    
    11.                 printf("Please input the second number:");
    12.                 scanf("%d", &b);
    13.    
    14.                 c = a + b;  //基本运算
    15.                 printf("The sum of %d+%d=%d\n", a, b, c);  //输出最终结果
    16.    
    17. }
    复制代码
    运行结果:
    1. Please input the first number:46
    2. Please input the second number:54
    3. The sum of 46+54=100
    复制代码


  • TA的每日心情
    奋斗
    2022-12-13 21:26
  • 签到天数: 371 天

    [LV.9]以坛为家II

     楼主| 发表于 2014-2-20 23:21:14 | 显示全部楼层
    特别说明的几点:
    1、#include <stdio.h>的意义在于main函数中引用了scanf()和printf()两个系统函数,因此必须要引进头文件;
    2、同时输入两个数还有另外一种写法scanf("%d,%d", a, b);这样一来在输入的时候就要按照分隔两个变量的“,”来分别输入,如输入4,5
    3、除了用“,”分隔以外,其他符号同样可以,比如空格,并且使用空格隔开在输入的时候可以使用“tab键”或“回车键”进行第二次输入;
    4、占位符"%d,%d"后面不能跟换行符“\n”。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    手机版|小黑屋|Archiver|iOS开发笔记 ( 湘ICP备14010846号 )

    GMT+8, 2024-5-3 17:04 , Processed in 0.050437 second(s), 23 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表