三、简单的输入输出

1、printf();

#include<stdio.h>

int main()
{
    
    printf("%d\n",23+43);
    //%d说明后面有一个整数要输出在这个位置上 
    printf("23+43=%d\n",23+43);
        
    return 0;
 }  

2、scanf();

#include<stdio.h>

int main()
{
    
    int price = 0;
    printf("请输入金额(元):");

    scanf("%d",&price);
    //要求scanf这个函数读入下一个整数,读到的结果赋值给变量price
    //小心price前面的&

    int change=100-price;
    printf("找您%d元。\n",change); 
    
    
    return 0;
 } 

如果输入的不是整数会怎样?

猜你喜欢

转载自www.cnblogs.com/Strugglinggirl/p/9026608.html
今日推荐