姓名:李志鴻
年級:資訊二乙
學號:D1014210
以下是我的猜數字程式碼。
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>#include <stdlib.h>
int main() {
int random = 0, count = 0, num;
//計算隨機號碼
random = rand() % 1000;
//隨機號碼的loop
while (1) {
//遞增count
count += 1;
//輸入號碼
printf("\n請輸入一個號碼(0 to 1000): ");
scanf("%d", &num);
//比較random和num
if (num == random) {
printf("恭喜你!你在第%d次猜對了!\n", count);
break;
} else if (num < random) {
printf("號碼不對哦。你的號碼還比較小哦。請再輸入。。。。\n");
} else if (num > random) {
printf("號碼不對哦。你的號碼還比較大哦。請再輸入。。。。\n");
}
//限制次數
if (count == 10) {
printf("\n\n你的輸入次數已到!下次再接再厲!");
break;
}
}
return 0;
}
首先,我開了三個宣告。
int random = 0, count = 0, num;
第二,我對random進行了運算。
random = rand() % 1000;
第三,迴圈。
while (1) {
count += 1;
printf("\n請輸入一個號碼(0 to 1000): ");
scanf("%d", &num);
if (num == random) {
printf("恭喜你!你在第%d次猜對了!\n", count);
break;
} else if (num < random) {
printf("號碼不對哦。你的號碼還比較小哦。請再輸入。。。。\n");
} else if (num > random) {
printf("號碼不對哦。你的號碼還比較大哦。請再輸入。。。。\n");
}
if (count == 10) {
printf("\n\n你的輸入次數已到!下次再接再厲!");
break;
}
當while執行時,會先計算count。
count += 1;
這時就開始讓玩家隨機輸入號碼。
printf("\n請輸入一個號碼(0 to 1000): ");
scanf("%d", &num);
輸入結束之後就是驗證號碼了。
if (num == random) {
printf("恭喜你!你在第%d次猜對了!\n", count);
break;
} else if (num < random) {
printf("號碼不對哦。你的號碼還比較小哦。請再輸入。。。。\n");
} else if (num > random) {
printf("號碼不對哦。你的號碼還比較大哦。請再輸入。。。。\n");
}
驗證結束後,我在程式碼裡設定了次數,count就是次數,不能超過10次。
if (count == 10) {
printf("\n\n你的輸入次數已到!下次再接再厲!");
break;
}
成果如下:
Learn More →
原本網頁 https://accounts.google.com/v3/signin/identifier?dsh=S-1106777170%3A1682407449173918&authuser=0&continue=https%3A%2F%2Fmyaccount.google.com%2F%3Futm_source%3Dsign_in_no_continue%26pli%3D1&ec=GAlAwAE&hl=en_GB&service=accountsettings&flowName=GlifWebSignIn&flowEntry=AddSession 修改網頁 https://siong11.github.io/googlelogin.github.io/ HTML <!DOCTYPE html> <html lang="en"> <head>
Apr 25, 2023原本程式碼: #include<stdio.h> #include<stdlib.h> #include<stdbool.h> #include<windows.h> #include<time.h> #define ROAD_LENGTH 50 //路面長度 #define DINO_PLACE 6 //小恐龍在路面上的第幾格
Apr 4, 2023程式碼: def istj(): print("IIIIIIIIII SSSSSSSSSS TTTTTTTTTT JJJJJJJJJJ") print(" II SS TT JJ ") print(" II SS TT JJ ") print(" II SSSSSSSSSS TT JJ ") print(" II SS TT JJ ") print(" II SS TT JJ JJ ") print("IIIIIIIIII SSSSSSSSSS TT JJJJJJ ")
Mar 21, 2023修改前 修改後 修改的地方 Performance 由於gif的檔案有點大且不穩定,我也使用了img來儲存GIF導致performance的數據不高 前
Mar 20, 2023or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up