2016年3月27日 星期日

寫一個 9x9 乘法表 swtch.... case

//4)利用  switch …case  Serial.print  Serial.println 指令


void setup()
{
 Serial.begin(9600); 
}
void loop()
{
 for (int i=1 ;i<=9 ;i++)
  {
    switch (i) {
    case 1 :  {
     for (int j=1 ; j<=9;j++)
     {
      int x=1*j; 
      Serial.print ("1") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
  } //case
  
    case 2 :  {
     for (int j=1 ; j<=9;j++)
     {
      int x=2*j; 
      Serial.print ("2") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
  } //case
  
   case 3 :  {
     for (int j=1 ; j<=9;j++)
     {
      int x=3*j; 
      Serial.print ("3") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
  } //case

   case 4 :  {
     for (int j=1 ; j<=9;j++)
     {
      int x=4*j; 
      Serial.print ("4") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
  } //case
   
  case 5 :  {
     for (int j=1 ; j<=9;j++)
     {
      int x=5*j; 
      Serial.print ("5") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
  } //case

    case 6 :  {
    for (int j=1 ; j<=9;j++)
     {
      int x=6*j; 
      Serial.print ("6") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
   } //case


    case 7 :  {
    for (int j=1 ; j<=9;j++)
     {
      int x=7*j; 
      Serial.print ("7") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
  } //case

   case 8 :  {
    for (int j=1 ; j<=9;j++)
     {
      int x=8*j; 
      Serial.print ("8") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
  } //case

    default :  {
    for (int j=1 ; j<=9;j++)
     {
      int x=9*j; 
      Serial.print ("9") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for 
     
    } //case
     
 //============================
  }  //switch
  
  }   //for
  
}  //loop

沒有留言:

張貼留言

Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3

  Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3 AngularJS 實例 <!DOCTYPE html> <html> <head> <meta charse...