Chapter 4 conditionals and loops
- 15. 15
九九乘法表
int i, j;
for (i=1; i<10; ++i)
for (j=1; j<10; ++j)
{
cout << i << “*” << j << “=“ << i*j << “ ”; // (命令列程式)
if (j == 9)
cout << endl;
}
- 16. // 在螢幕上印出一九九乘法表
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j;
for (i=1; i<10; ++i)
{
for (j=1; j<10; ++j)
{
printf(“%2d * %2d = %2dt”, i, j, i*j);
}
printf(“n”);
}
printf(“按任意鍵繼續!”);
_getch();
}
16
- 17. // 在螢幕上印出一九九乘法表
#include <iostream>
#include <conio.h>
using std::cout;
using std::endl;
int main()
{
int i, j;
for (i=1; i<10; ++i)
{
for (j=1; j<10; ++j)
{
cout << i << "*" << j << "=";
cout.width(2);
cout << i*j << " ";
}
cout << endl;
}
cout << "n按任意鍵繼續!";
_getch();
return 0;
}
17
- 18. 1. using System;
2. using System.Collections.Generic;
3. using System.Text;
4. namespace ConsoleApplication_DoubleLoop
5. {
6. class Program
7. {
8. static void Main(string[] args)
9. {
10. int i, j;
11. for (i = 1; i < 10; ++i)
12. {
13. for (j = 1; j < 10; ++j)
14. if (i * j > 9)
15. Console.Write("{0}*{1}={2} ", i, j, i * j);
16. else
17. Console.Write("{0}*{1}={2} ", i, j, i * j);
18. Console.Write('n');
19. }
20. Console.Read(); // 利用此敘述讓程式暫停
21. } } }
18
- 21. 將二進制轉換成十進制
◦ 二進制的數字 1101000 等值十進制的那個值?
21
1 x 26 = 1 x 64 = 64
+ 1 x 25 = 1 x 32 = 32
+ 0 x 24 = 0 x 16 = 0
+ 1 x 23 = 1 x 8 = 8
+ 0 x 22 = 1 x 4 = 0
+ 0 x 21 = 1 x 2 = 0
+ 0 x 2º = 0 x 1 = 0
= 104