# C補充資料
## 輸入輸出
**C++:**
cin、cout
**範例:**
以整數型態為例
```
int i;
cin >> i;
cout << i ;
輸入1則執行結果為1
```
**C**:
scanf、printf
變數型態(常用):
* %d(整數型態int)
* 10、3、15
* %f(浮點數\小數型態float、double)
* 1.5、0.3、0.4
* %c(字元型態char)
* 'A'、'a'
* %s(字元陣列型態)
* "Hello World"
**範例:**
```
int i;
scanf("%d",&i);
printf("%d",i);
輸入1則執行結果為1
```
## 排版
```
#include <iostream>
using namespace std;
int main()
{
int a=11,b=111;
printf("%3d\n%3d",a,b);
return 0;
}
// 11
//111
```
%+數字(代表預留幾格空間)+變數型態代表(d、f、c等)
+(可省略)代表向右對齊,-(不可省略)代表向左對齊
```
#include <iostream>
using namespace std;
int main()
{
int a=11,b=111;
printf("%3d\n%3d",a,b);
return 0;
}
//11
//111
```
排版的話C比C++好用好多ㄛ
然後這個語法在python也是可行的!
有興趣的看這邊:https://savingking.com.tw/blog/post/print
另外也可以控制小數點輸出
```
#include <iostream>
using namespace std;
int main()
{
double a=0.11,b=0.111;
printf("%.3f\n%.3f",a,b);
return 0;
}`