一、判斷0~10之間,當循環I=3時候跳出當前循環,當I等於8時候,退出當前循環。spa
1 procedure Countand(); 2 var 3 I: Integer; 4 begin 5 for I := 0 to 10 do 6 begin 7 Writeln(I); 8 if I = 3 then 9 begin 10 Writeln('跳過當前'); 11 Continue; 12 end; 13 if I = 8 then 14 begin 15 Writeln('跳出循環'); 16 Break; 17 end; 18 end; 19 20 end; 21 22 begin 23 Countand(); 24 Readln; 25 end.
二、1~100 數字相加code
1 procedure Sum1(); 2 var 3 num1,sumnums : Integer; 4 begin 5 sumnums := 0; 6 for num1 := 1 to 100 do // for 循環 7 begin 8 sumnums := num1 + sumnums; //將1-100數字進行相加 9 end; 10 Writeln(sumnums); //屏幕輸出計算結果 11 end; 12 13 procedure Sum2(); 14 var 15 num2,sumnum2 : Integer; 16 begin 17 num2 := 0; 18 sumnum2 := 0; 19 while num2 < 100 do //while 循環 20 begin 21 num2 := num2 + 1; 22 Writeln('num2_value:',num2); 23 sumnum2 := num2 + sumnum2; //將1-100數字進行相加 24 end; 25 Writeln('eventuate:',sumnum2); //屏幕輸出計算結果 26 end; 27 28 procedure Sum3(); 29 var 30 num3,sumnum3 : Integer; 31 begin 32 num3 := 0; 33 sumnum3 := 0; 34 repeat //repeat 循環 35 num3 := num3+1; 36 Writeln(num3);//屏幕輸出num3 1-100的數字 37 sumnum3 := num3 + sumnum3; //將1-100數字進行相加 38 39 until (num3 > 99); 40 Writeln(sumnum3); //屏幕輸出計算結果 41 end; 42 43 begin 44 // Sum1(); 45 // Sum2(); 46 Sum3(); 47 Readln; 48 end.
三、打印1-100 之間全部7的倍數的證書的個數及總和(體會設置計算器的思想)blog
1 procedure Counter(); 2 var 3 i : Integer; 4 Sumnum1 : Integer; //求和 5 Amont : Integer; //統計個數 6 begin 7 Sumnum1 := 0; 8 Amont := 0; 9 for i := 1 to 100 do 10 begin 11 if (i mod 7) = 0 then 12 begin 13 // Writeln(i); 14 Sumnum1 := Sumnum1 + i; 15 Amont := Amont + 1; 16 end; 17 end; 18 Writeln(Sumnum1,' ',Amont); 19 end; 20 begin 21 Counter(); 22 Readln; 23 end.
四、輸出全部的水仙花數,所謂水仙花數指一個3位數,其個位上數字立方和等於其自己ip
1 procedure Narcissistic_number(); 2 var 3 Ones : Integer; //個位 4 Tens : Integer; //十位 5 Hundreds : Integer; //百位 6 Narcissistic_number :Integer; //水仙花數 7 begin 8 for Narcissistic_number := 100 to 999 do 9 begin 10 // Narcissistic_number := 153; 11 Hundreds := Narcissistic_number div 100; 12 Tens := (Narcissistic_number mod 100) div 10; 13 Ones := (Narcissistic_number mod 100) mod 10; 14 // Writeln(Hundreds, ',', Tens, ',', Ones); 15 16 if (Hundreds*Hundreds*Hundreds+Tens*Tens*Tens+Ones*Ones*Ones) = Narcissistic_number then 17 begin 18 Writeln(Narcissistic_number) 19 end; 20 21 end; 22 23 end; 24 25 begin 26 // Counter(); 27 Narcissistic_number(); 28 Readln; 29 end.
五、9*9乘法表ci
1 procedure Multiplication_Table(); 2 var 3 Height,Width : Integer; 4 begin 5 for Height := 1 to 9 do 6 begin 7 for Width := 1 to Height do 8 begin 9 // #$09 製表符 10 Write(Height,'x',Width,'=',(Height*Width), #$09); 11 end; 12 Writeln(''); 13 end; 14 15 end; 16 begin 17 Multiplication_Table(); 18 Readln; 19 end.
六、在控制檯上打印輸出一個三角形的圖案(參考9*9乘法表)it
1 procedure Triangular_pattern(); 2 var 3 num1,num2 : Integer; 4 begin 5 for num1 := 1 to 9 do 6 begin 7 for num2 := 1 to num1 do 8 begin 9 Write('*'); 10 end; 11 Writeln(''); 12 end; 13 end; 14 begin 15 Triangular_pattern(); 16 Readln; 17 end.