日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言明解课后答案,明解C语言 中级篇 第一章答案

發布時間:2023/12/3 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言明解课后答案,明解C语言 中级篇 第一章答案 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

練習1-1

#include

#include

int main() {

srand(time(0));

int anw = rand() % 7;

printf("您的簽運是:");

switch (anw) {

case 0:printf("大吉"); break;

case 1:printf("吉"); break;

case 2:printf("小吉"); break;

case 3:printf("吉"); break;

case 4:printf("末吉"); break;

case 5:printf("兇"); break;

case 6:printf("大兇"); break;

}

}

練習1-2

#include

#include

int main() {

srand(time(0));

int anw = rand() %10;

printf("您的簽運是:");

switch (anw) {

case 0:

case 1:printf("大吉"); break;

case 2:

case 3:printf("吉"); break;

case 4:

case 5:

case 6:printf("小吉"); break;

case 7:printf("末吉"); break;

case 8:printf("兇"); break;

case 9:printf("大兇"); break;

}

}

練習1-3

/* 猜數游戲(其五:顯示輸入記錄)*/

#include

#include

#include

#define MAX_STAGE 12 /* 最多可以輸入的次數 */

int main(void)

{

int i;

int stage; /* 已輸入的次數 */

int no; /* 讀取的值 */

int ans; /* 目標數字 */

int num[MAX_STAGE]; /* 讀取的值的歷史記錄 */

srand(time(NULL)); /* 設定隨機數的種子 */

ans = rand() % 1998-999; /* 生成-999~999的隨機數 */

printf("請猜一個-999~999的整數。\n\n");

stage = 0;

do {

printf("還剩%d次機會。是多少呢:", MAX_STAGE - stage);

scanf("%d", &no);

num[stage++] = no; /* 把讀取的值存入數組 */

if (no > ans)

printf("\a再小一點。\n");

else if (no < ans)

printf("\a再大一點。\n");

} while (no != ans && stage < MAX_STAGE);

if (no != ans)

printf("\a很遺憾,正確答案是%d。\n", ans);

else {

printf("回答正確。\n");

printf("您用了%d次猜中了。\n", stage);

}

puts("\n--- 輸入記錄 ---");

for (i = 0; i < stage; i++)

printf(" %2d : %4d %+4d\n", i + 1, num[i], num[i] - ans);

return 0;

}

練習1-4

/* 猜數游戲(其五:顯示輸入記錄)*/

#include

#include

#include

#define MAX_STAGE 12 /* 最多可以輸入的次數 */

int main(void)

{

int i;

int stage; /* 已輸入的次數 */

int no; /* 讀取的值 */

int ans; /* 目標數字 */

int num[MAX_STAGE]; /* 讀取的值的歷史記錄 */

srand(time(NULL)); /* 設定隨機數的種子 */

ans = 3*(rand() %333)+3; /* 生成3~999之間3的倍數的隨機數 */

printf("請猜一個3~999的而且是3的倍數整數。\n\n");

stage = 0;

do {

printf("還剩%d次機會。是多少呢:", MAX_STAGE - stage);

scanf("%d", &no);

while(no % 3 != 0) {

printf("請輸入3的倍數:");

scanf("%d", &no);

}

num[stage++] = no; /* 把讀取的值存入數組 */

if (no > ans)

printf("\a再小一點。\n");

else if (no < ans)

printf("\a再大一點。\n");

} while (no != ans && stage < MAX_STAGE);

if (no != ans)

printf("\a很遺憾,正確答案是%d。\n", ans);

else {

printf("回答正確。\n");

printf("您用了%d次猜中了。\n", stage);

}

puts("\n--- 輸入記錄 ---");

for (i = 0; i < stage; i++)

printf(" %2d : %4d %+4d\n", i + 1, num[i], num[i] - ans);

return 0;

}

/* 猜數游戲(其五:顯示輸入記錄)*/

#include

#include

#include

#define MAX_STAGE 12 /* 最多可以輸入的次數 */

int main(void)

{

int i;

int stage; /* 已輸入的次數 */

int no; /* 讀取的值 */

int ans; /* 目標數字 */

int num[MAX_STAGE]; /* 讀取的值的歷史記錄 */

srand(time(NULL)); /* 設定隨機數的種子 */

ans = 3*(rand() %333)+3; /* 生成3~999之間3的倍數的隨機數 */

printf("請猜一個3~999的而且是3的倍數整數。\n\n");

stage = 0;

do {

printf("還剩%d次機會。是多少呢:", MAX_STAGE - stage);

scanf("%d", &no);

if (no % 3 != 0) {

break;

}

num[stage++] = no; /* 把讀取的值存入數組 */

if (no > ans)

printf("\a再小一點。\n");

else if (no < ans)

printf("\a再大一點。\n");

} while (no != ans && stage < MAX_STAGE);

if (no != ans)

printf("\a很遺憾,正確答案是%d。\n", ans);

else {

printf("回答正確。\n");

printf("您用了%d次猜中了。\n", stage);

}

puts("\n--- 輸入記錄 ---");

for (i = 0; i < stage; i++)

printf(" %2d : %4d %+4d\n", i + 1, num[i], num[i] - ans);

return 0;

}

練習1-5

/* 猜數游戲(其五:顯示輸入記錄)*/

#include

#include

#include

int main(void)

{

int i;

int stage; /* 已輸入的次數 */

int no;

int cnt=0;/* 讀取的值 */

int d1, d2, ans; /* 目標數字 */

srand(time(NULL)); /* 設定隨機數的種子 */

d1 = rand();

d2 = rand();

int max = (d2 > d1) ? d2 : d1;

int min = (d2 < d1) ? d2 : d1;

ans = (rand() % (max -min))+min;

int x = (max - min);

printf("請猜一個%d~%d的整數\n\n", min, max);

while (x > 50)

{

x /= 2;

cnt++; }

cnt += 3;

int num[128]; /* 讀取的值的歷史記錄 */

stage = 0;

do {

printf("還剩%d次機會。是多少呢:", cnt- stage);

scanf("%d", &no);

num[stage++] = no; /* 把讀取的值存入數組 */

if (no > ans)

printf("\a再小一點。\n");

else if (no < ans)

printf("\a再大一點。\n");

} while (no != ans && stage < cnt);

if (no != ans)

printf("\a很遺憾,正確答案是%d。\n", ans);

else {

printf("回答正確。\n");

printf("您用了%d次猜中了。\n", stage);

}

puts("\n--- 輸入記錄 ---");

for (i = 0; i < stage; i++)

printf(" %2d : %4d %+4d\n", i + 1, num[i], num[i] - ans);

return 0;

}

練習1-6

/* 猜數游戲(其五:顯示輸入記錄)*/

#include

#include

#include

#define MAX_STAGE 6 /* 最多可以輸入的次數 */

int main(void)

{

int i;

int stage; /* 已輸入的次數 */

int no; /* 讀取的值 */

int ans; /* 目標數字 */

int num[MAX_STAGE]; /* 讀取的值的歷史記錄 */

int choice, d;

srand(time(NULL));

printf("請選擇難度等級(1)1~9 (2)1~99 (3)1~999 (4)1~9999:");

scanf("%d", &choice);

if (choice == 1){

ans = rand() % 8 + 1;

d = 9;

}

if (choice == 2) {

ans = rand() % 98 + 1;

d = 99;

}

if (choice == 3) {

ans = rand() % 998 + 1;

d = 999;

}

if (choice == 4) {

ans = rand() % 9998 + 1;

d = 999;

}

printf("請猜一個1~%d的整數。\n\n",d);

stage = 0;

do {

printf("還剩%d次機會。是多少呢:", MAX_STAGE - stage);

scanf("%d", &no);

num[stage++] = no; /* 把讀取的值存入數組 */

if (no > ans)

printf("\a再小一點。\n");

else if (no < ans)

printf("\a再大一點。\n");

} while (no != ans && stage < MAX_STAGE);

if (no != ans)

printf("\a很遺憾,正確答案是%d。\n", ans);

else {

printf("回答正確。\n");

printf("您用了%d次猜中了。\n", stage);

}

puts("\n--- 輸入記錄 ---");

for (i = 0; i < stage; i++)

printf(" %2d : %4d %+4d\n", i + 1, num[i], num[i] - ans);

return 0;

}

練習1-7

/* 猜數游戲(其五:顯示輸入記錄)*/

#include

#include

#include

#define MAX_STAGE 10 /* 最多可以輸入的次數 */

int main(void)

{

int i;

int stage; /* 已輸入的次數 */

int no; /* 讀取的值 */

int ans; /* 目標數字 */

int num[MAX_STAGE]; /* 讀取的值的歷史記錄 */

srand(time(NULL)); /* 設定隨機數的種子 */

ans = rand() % 1000; /* 生成0~999的隨機數 */

printf("請猜一個0~999的整數。\n\n");

stage = 0;

do {

printf("還剩%d次機會。是多少呢:", MAX_STAGE - stage);

scanf("%d", &no);

num[stage++] = no; /* 把讀取的值存入數組 */

if (no > ans)

printf("\a再小一點。\n");

else if (no < ans)

printf("\a再大一點。\n");

} while (no != ans && stage < MAX_STAGE);

if (no != ans)

printf("\a很遺憾,正確答案是%d。\n", ans);

else {

printf("回答正確。\n");

printf("您用了%d次猜中了。\n", stage);

}

puts("\n--- 輸入記錄 ---");

for (i = 0; i < stage; i++) {

printf(" %2d : %4d ", i + 1, num[i]);

if(num[i] - ans==0)

printf("%4d\n", num[i] - ans);

else {

printf("%+4d\n", num[i] - ans);

}

}

return 0;

}

練習1-8

/* 猜數游戲(其五:顯示輸入記錄)*/

#include

#include

#include

#define MAX_STAGE 10 /* 最多可以輸入的次數 */

int main(void)

{

int i;

int stage; /* 已輸入的次數 */

int no; /* 讀取的值 */

int ans; /* 目標數字 */

int num[MAX_STAGE]; /* 讀取的值的歷史記錄 */

srand(time(NULL)); /* 設定隨機數的種子 */

ans = rand() % 1000; /* 生成0~999的隨機數 */

printf("請猜一個0~999的整數。\n\n");

stage = 0;

i = 0;

for(i=0;i

printf("還剩%d次機會。是多少呢:", MAX_STAGE - stage);

scanf("%d", &no);

num[stage++] = no; /* 把讀取的值存入數組 */

if (no > ans) {

printf("\a再小一點。\n");

}

if (no < ans){

printf("\a再大一點。\n");

}

if(ans==no){

break;

}

}

if (no != ans)

printf("\a很遺憾,正確答案是%d。\n", ans);

else {

printf("回答正確。\n");

printf("您用了%d次猜中了。\n", stage);

}

puts("\n--- 輸入記錄 ---");

for (i = 0; i < stage; i++) {

printf(" %2d : %4d ", i + 1, num[i]);

if(num[i] - ans==0)

printf("%4d\n", num[i] - ans);

else {

printf("%+4d\n", num[i] - ans);

}

}

return 0;

}

總結

以上是生活随笔為你收集整理的c语言明解课后答案,明解C语言 中级篇 第一章答案的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。