1 1 12 includestdio h int main int

  • Slides: 14
Download presentation

練習 1 -1: 程式解答(1/2) #include<stdio. h> int main() { int pos = 23; int

練習 1 -1: 程式解答(1/2) #include<stdio. h> int main() { int pos = 23; int neg = -456; printf("練習 1 -1 學號: xxxx 姓名: xxxxnn"); printf("|123456789|n"); printf("|%d|n", pos); printf("|%2 d|n", pos); printf("|%9 d|n", pos); printf("|%+09 d|n", pos); printf("|%+-9 d|n", pos); printf("|%-9 d|n", pos); 7

練習 1 -1: 程式解答(2/2) printf("|%d|n", neg); printf("|%2 d|n", neg); printf("|%9 d|n", neg); printf("|%09 d|n",

練習 1 -1: 程式解答(2/2) printf("|%d|n", neg); printf("|%2 d|n", neg); printf("|%9 d|n", neg); printf("|%09 d|n", neg); printf("|%-9 d|n", neg); system("PAUSE"); return 0; } 8

練習 1 -2: 程式解答(1/2) #include <stdio. h> #include <stdlib. h> int main() { double

練習 1 -2: 程式解答(1/2) #include <stdio. h> #include <stdlib. h> int main() { double fl=21. 678; printf(“練習 1 -2 學號: xxxxx 姓名: xxxxnn"); printf("|123456789012345|n"); printf("|%-5. 2 f|n", fl); printf("|%15 f|n", fl); printf("|%-15. 4 f|n", fl); 10

練習 1 -2: 程式解答(2/2) printf("|%-15. 2 f|n", fl); printf("|%+-15 e|n", fl); printf("|%+-15. 3 e|n",

練習 1 -2: 程式解答(2/2) printf("|%-15. 2 f|n", fl); printf("|%+-15 e|n", fl); printf("|%+-15. 3 e|n", fl); system("PAUSE"); return 0; } 11

練習 1 -3: 程式解答(1/2) #include <stdio. h> #include <stdlib. h> int main() { double

練習 1 -3: 程式解答(1/2) #include <stdio. h> #include <stdlib. h> int main() { double fl=9. 876; char str[30]="How are you? "; printf(“練習 1 -3 學號: xxxxx 姓名: xxxxxnn"); printf("|123456789012345|n"); printf("|%-5. 2 f|n", fl); printf("|%15. 4 f|n", fl); printf("|%-15. 2 f|n", fl); printf("|%+-15 e|n", fl); printf("|%+-15. 3 e|n", fl); 13

練習 1 -3: 程式解答(2/2) printf("|%s|n", str); printf("|%15 s|n", str); printf("|%-15. 3 s|n", str); system("PAUSE");

練習 1 -3: 程式解答(2/2) printf("|%s|n", str); printf("|%15 s|n", str); printf("|%-15. 3 s|n", str); system("PAUSE"); return 0; } 14