Holey_yan

20140325_KUAS_VisualC++_BasicPrintStar

Mar 25th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. /****************************************/
  2. /** 20140325 Basic Print Star Example  **/
  3. /** Maker  : Yan                       **/
  4. /** E-Mail : [email protected]     **/
  5. /** Date   : 2014/03/25 am.10:18       **/
  6. /****************************************/
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. void main()
  12. {
  13.     //建立變數input, 此為輸入數值
  14.     int input = 0;
  15.  
  16.     /*for 之無窮迴圈使用方式為
  17.       for( ; ; ),相同於while(1)*/
  18.     for( ; ; )
  19.     {
  20.         printf("Input a number: ");
  21.         //輸入數值
  22.         scanf("%d", &input);
  23.  
  24.         //當input 為1 時跳出迴圈(break = 跳出迴圈)
  25.         if(input == -1){break;}
  26.  
  27.         //執行迴圈輸出星號
  28.         for(int i = 1; i <= input; i++)
  29.         {
  30.             printf("*");
  31.         }
  32.         //斷行
  33.         printf("\n");
  34.     }
  35.     system("pause");
  36. }
Advertisement
Add Comment
Please, Sign In to add comment