当前位置:网站首页>Input and output of scanf and printf (format controller)
Input and output of scanf and printf (format controller)
2022-04-22 05:10:00 【Programming Xiaopeng】
One 、 Use scanf Input and printf Output
These two functions are C In language
1、scanf Use
Format :
scanf(" Format control ", Variable address );
scanf("%d",&n);
Of common data type variables scanf Format symbol
| int | %d |
|---|---|
| long long | %lld |
| float | %f |
| char | %c |
| double | %lf |
| character string (char Array ) | %s |
image 13:45:20 You can type it like this
scanf("%d:%d:%d",&h,&m,&s);
except %c Outside ,scanf The input of other format characters is with the blank character ( Space 、Tab) Is the end judgment flag , The character array uses %s When reading in, use space and line feed as the sign of the end of reading ,%c You can read spaces and line breaks .
2、printf Use
printf(" Format control ", Variable name );
The format controller has only double Turn into %f
If you want to output % , Just add one in front % \
Two 、 Common output formats
1、%md
Can make insufficient m Bit int Type variable With m Bit right aligned output , Fill in the high order with blank space , If itself exceeds m Bits remain the same .
#include<iostream>
using namespace std;
int main()
{
int a=123,b=123456;
printf("%5d\n",a);
printf("%5d\n",b);
return 0;
}
123
123456
2、%0md
And %md The difference is , When the variable is insufficient m When a , Make up 0.
#include<iostream>
using namespace std;
int main()
{
int a=123,b=123456;
printf("%5d\n",a);
printf("%5d\n",b);
printf("%05d\n",a);
return 0;
}
123
123456
00123
3、%.mf
You can keep floating point numbers m Decimal output
#include<iostream>
using namespace std;
int main()
{
double d=3.14159;
printf("%.0f\n",d);
printf("%.1f\n",d);
printf("%.2f",d);
return 0;
}
3
3.1
3.14
3、 ... and 、 Use getchar Input 、putchar Output single character
Can recognize line breaks
char c1,c2;
c1=getchar();
c2=getchar();
putchar(c1);
putchar(c2);
版权声明
本文为[Programming Xiaopeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220508378683.html
边栏推荐
- The problem that the video in video becomes muted when the mouse scrolls
- Flutter installation summary
- If the answer is yes or no, do you want to use one checkbox or two radio boxes? Which is more appropriate? Why?
- Jackson
- Programme de démarrage Spark: WordCount
- cv2.drawContours()、cv2.findContours()、cv2.boundingRect(img)函数用法解析
- Chapter IX user and authority
- Overview of over fitting and under fitting treatment methods of linear regression
- The urlcode of PHP cannot restore the original URL
- JVM - common parameters
猜你喜欢

数据库第十三次作业 事务管理

Chapter 6 Association query

2022.04.20 Huawei written examination

Chapter 2 MySQL data types and operators
Not sure whether it is a bug or a setting

Discussion on data set division

EMO-DB 數據集的 Speech 特征提取

How to initiate mqtt 100 million connection and 10 million message throughput performance test

Generic types in classes and generic types

Swagger UI简介
随机推荐
Data distribution, correlation analysis and visualization method of data exploratory analysis (EDA)
scanf、printf的输入输出(格式控制符)
Chapter 3 basic SQL syntax
Final Cut Pro mosaics in multiple places of the video at the same time
Joint type and type protection
Acrobat Pro DC tutorial: how to create PDF using text and picture files?
[Reading Notes - > statistics] 07-03 introduction to the concept of discrete probability distribution Poisson distribution
Esp32 vhci realizes ble broadcasting, which is so magical
cv2.drawContours()、cv2.findContours()、cv2.boundingRect(img)函数用法解析
ObjectBox使用记录
【Pytorch】Tensor. Use and understanding of continguous()
Enum enumeration type
Speech feature extraction of emo-db dataset
KNN prediction minimum case summary
Regular expression validation
2022-4-20 operation
A collection of common methods of data exploratory analysis (EDA)
Go array slice
常见的测试方式
RestFul风格的API设计