Skip to content

Instantly share code, notes, and snippets.

@ruyut
Created March 28, 2019 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruyut/5dff28438f860585395af800858d855e to your computer and use it in GitHub Desktop.
Save ruyut/5dff28438f860585395af800858d855e to your computer and use it in GitHub Desktop.
//903
#include<stdlib.h>
#include<stdio.h>
int greater60(int*, int);//宣告整數greater60,要傳入整數記憶體位址和整數
int main() {
int data[6];//宣告整數陣列
int i;//宣告整數
for (i = 0; i<6; i++) {//i從0開始到5,共會出現6次
printf("請輸入第%d個分數:", i + 1);//顯示文字和i+1(1~6)
scanf("%d", &data[i]);//讓使用者輸入數字
}
printf("\n您輸入的資料如下:\n");//列印文字
for (i = 0; i<6; i++)//i從0開始到5,共會出現6次
printf("data[%d]:%d\n", i, data[i]);//列印文字和整數陣列內的變數並換行
printf("大於60分得有:%d個\n", greater60(data, 6));//列印文字並呼叫greater60且傳入
system("PAUSE");//等待使用者按下任意按鍵 整數記憶體位址和變數
return 0;//跳出
}
int greater60(int* dt, int n) {//傳入陣列的記憶體位址和陣列大小
int i, ch = 0;
for (i = 0; i<n; i++) {
if (dt[i] >= 60)//檢查陣列內的變數是否大於等於60
ch++;//如果有大於等於60的數字ch就加1
}
return ch;//回傳有大於等於60的數字個數
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment