Archive for 十月, 2009

20091029CP

作業5和小考及期中上機考公告

作業5和小考及期中上機考公告

本週程式設計的新加元素:陣列及檔案讀寫

本週程式設計的新加元素:陣列及檔案讀寫

利用fscanf()讀入成績檔案,並放到一個成績的陣列中

利用fscanf()讀入成績檔案,並放到一個成績的陣列中

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

29
十月

Ch程式設計:練習五

   Posted by: admin    in 98(上)C程式設計

#include <stdio.h>
 
main()
{
   int ret, i, ss, sum, average, count;
   int score[100];
   FILE * stream;
   char filename[20]="score.txt";
   if( (stream  = fopen( filename, "r" )) == NULL )
   {
      printf( "The file %s was not opened\n", filename );
      return -1;
   }
   i=0; sum=0; count=0;
   ret = fscanf(stream, "%d\n", &ss);
 
   while (ret !=  EOF)
   {
         score[i++]=ss;
         sum +=ss;
         ret = fscanf(stream, "%d\n", &ss);
   }
   fclose(stream);
 
   count=i;
   if (count >0)
      average = sum/count;
   else
       average = -1;
 
   for (i=0; i< count; i++)
   {
       if (score[i] >=average)
          printf("%d\n", score[i]);
   }
 
   return 0;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: ,

20091029IProg

互動程式專題設計討論(1):互動繪本

互動程式專題設計討論(1):互動繪本

互動程式專題設計討論(2):音樂星球

互動程式專題設計討論(2):音樂星球

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

20091022CP

習題一說明

習題一說明

習題2說明:列印出一個空心的正方形和實心的菱形

習題2說明:列印出一個空心的正方形和實心的菱形

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

// The setup() method runs once, when the sketch starts
int ledR1 =  2;    // Red LED input at digital pin 2
int ledR2 =  3;    // Red LED input at digital pin 3
int ledR3 =  4;    // Red LED input at digital pin 4
 
void setup()   {                
  // initialize the digital pin as an output:
  pinMode(ledR1, OUTPUT);    
  pinMode(ledR2, OUTPUT);   
  pinMode(ledR3, OUTPUT);    
}
 
// the loop() method runs over and over again,
// as long as the Arduino has power
 
void loop()                     
{
 
  // if it is, the buttonState is HIGH:
    Led1();
    delay(500);
    Led2();
    delay(600);
    Led3();
    delay(700);
    Led4();
    delay(800);
    Led5();
    delay(900);
    Led6();
    delay(1000);
    Led7();
    delay(800);
    Led5();
    delay(600);
    Led3();
    delay(400);
    Led1();
    delay(500);
    Led2();
    delay(600);
    Led4();
    delay(700);
    Led6();
    delay(800);
    Led7();
    delay(900);
  }
  void NO()
  {
    digitalWrite(ledR1, LOW);  
    digitalWrite(ledR2, LOW);  
    digitalWrite(ledR3, LOW); 
  }
  void Led1()
  {
    digitalWrite(ledR1, HIGH);  
    digitalWrite(ledR2, LOW);  
    digitalWrite(ledR3, LOW); 
  }
  void Led2()
  {
    digitalWrite(ledR1, LOW);  
    digitalWrite(ledR2, HIGH);  
    digitalWrite(ledR3, LOW); 
  }
  void Led3()
  {
    digitalWrite(ledR1, HIGH);  
    digitalWrite(ledR2, HIGH);  
    digitalWrite(ledR3, LOW); 
  }
  void Led4()
  {
    digitalWrite(ledR1, LOW);  
    digitalWrite(ledR2, LOW);  
    digitalWrite(ledR3, HIGH); 
  }
  void Led5()
  {
    digitalWrite(ledR1, HIGH);  
    digitalWrite(ledR2, LOW);  
    digitalWrite(ledR3, HIGH); 
  }
  void Led6()
  {
    digitalWrite(ledR1, LOW);  
    digitalWrite(ledR2, HIGH);  
    digitalWrite(ledR3, HIGH); 
  }
  void Led7()
  {
    digitalWrite(ledR1, HIGH);  
    digitalWrite(ledR2, HIGH);  
    digitalWrite(ledR3, HIGH); 
  }

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: