3--2C标准输入输出的力例题

本文详细介绍了C语言中基本格式化输入输出的方法,并通过示例展示了如何使用转换说明符进行不同数据类型的输入和输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//C标准输入输出的力例题 
#include<iostream.h>
int main()
{
    int num1;
    float num2;
    char ch1;
    int na,nb,nc,nd,ne,nf,ng;
    double da,db,dc;
    //基本格式化输入输出
    
    printf("------------------Basic input and output-------------------\n");
                             //输出时无参数,仅输出字符串
   printf("Please input a chracter, a tineger and a float:");
                              //提示用户输入数据
    scanf("%c %d %f",&ch1,&num1,&num2);
                                //依次读取字符,整数和浮点数分别存入ch1,num1,num2
    printf("Input data are:ch1=%c,num1=%d,num2=%f\n",ch1,num1,num2);
                                 //输出读取的用户数据 
     
    //转换说明符的使用
    
    printf("\n----------Scanf with conversion specifier-----------------\n");
    
    //整数
    
    printf("Please enter seven integers:");
    
    scanf("%d%i%i%i%o%u%x",&na,&nb,&nc,&nd,&ne,&nf,&ng); 
    
    printf("The input displayed as decimal intgers is:\n");
    
    
    printf("%d %d %d %d %d %d %d\n",na,nb,nc,ne,nf,ng);
    
    //浮点数
    printf("\nEnter three foating--point numbers:");
    
    scanf("%lf%le%lg",&da,&db,&dc);
    
    printf("Here are the numbers entered in plain foating -point notation:\n");
    
    printf("%f\n%f\n%f\n",da,db,dc);
    
    return 0;
    
    
    
    
     
    
    
    
}  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值