二維碼
微世推網(wǎng)

掃一掃關(guān)注

當(dāng)前位置: 首頁(yè) » 快報(bào)資訊 » 今日快報(bào) » 正文

C語(yǔ)言經(jīng)典100例——31_35

放大字體  縮小字體 發(fā)布日期:2023-04-28 11:52:32    作者:葉之漓    瀏覽次數(shù):241
導(dǎo)讀

感覺(jué)這里只有題目31 和 題目 34 有用,其他得調(diào)顏色得應(yīng)該絕大部分人用不到(題目 31題目:請(qǐng)輸入星期幾得第壹個(gè)字母來(lái)判斷一下是星期幾,如果第壹個(gè)字母一樣,則繼續(xù)判斷第二個(gè)字母。程序分析:用情況語(yǔ)句比較好,

感覺(jué)這里只有題目31 和 題目 34 有用,其他得調(diào)顏色得應(yīng)該絕大部分人用不到(

題目 31

題目:請(qǐng)輸入星期幾得第壹個(gè)字母來(lái)判斷一下是星期幾,如果第壹個(gè)字母一樣,則繼續(xù)判斷第二個(gè)字母。

程序分析:用情況語(yǔ)句比較好,如果第壹個(gè)字母一樣,則判斷用情況語(yǔ)句或if語(yǔ)句判斷第二個(gè)字母。

#include<cstdio>int main(){ char c; /gov這里需要一個(gè)一個(gè)輸入單詞才專(zhuān)業(yè)解決問(wèn)題,想想能不能一行解決gov/ while ((c=getchar())!='Y') /gov當(dāng)所按字母為Y時(shí)才結(jié)束gov/ { switch (c) { case 'S': printf("please input second letter\n"); if((c=getchar()) == 'a') printf("Saturday\n"); if ((c=getchar())== 'u') printf("Sunday\n"); break; case 'F':printf("Friday\n");break; case 'M':printf("Monday\n");break; case 'T':printf("please input second letter\n"); if((c=getchar())=='u') printf("Tuesday\n"); else if ((c=getchar())=='h') printf("Thursday\n"); break; case 'W':printf("Wednesday\n");break; default: break; } }}題目 32

題目:Press any key to change color, do you want to try it. Please hurry up!

#include<conio.h>#include<windows.h>#include<cstdio>// 此部分來(lái)自: https://blog.csdn.net/u012133341/article/details/81487802// 這里本人不太理解。 int textbackground(short iColor){ HANDLE hd = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO csbInfo; GetConsoleScreenBufferInfo(hd, &csbInfo); return SetConsoleTextAttribute(hd, (iColor<<4)|(csbInfo.wAttributes&~0xF0));}int main(){ for(int color = 0;color < 8 ;color++) { textbackground(color); printf("This is color %d\r\n",color); printf("Press any key to continue\n"); getch();//與getchar不同得是,getch專(zhuān)業(yè)看不到字符 }}題目 33

題目:學(xué)習(xí)gotoxy()與clrscr()函數(shù)

#include<cstdio>#include<conio.h>#include<windows.h>// 此部分來(lái)自: https://blog.csdn.net/u012133341/article/details/81487802// 這里本人不太理解。 int textbackground(short iColor){ HANDLE hd = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO csbInfo; GetConsoleScreenBufferInfo(hd, &csbInfo); return SetConsoleTextAttribute(hd, (iColor<<4)|(csbInfo.wAttributes&~0xF0));}// 建議讀者自行尋求資料。。 這里不打算深究 void gotoxy(int x, int y){ COORD coord; coord.X = x; coord.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);}int main(){ system("cls");//清屏 gotoxy(1,5); textbackground(3); printf("Output at row 5 col 1\n"); gotoxy(20,10); textbackground(2); printf("Output at row 10 col 20\n");}題目 34

題目:練習(xí)函數(shù)調(diào)用

#include<cstdio>void output_error()// 函數(shù)聲明,void類(lèi)型,最后專(zhuān)業(yè)加return;{ printf("error!"); return;}int main(){ output_error();//知道怎嗎調(diào)用即可。這里不打算介紹參數(shù) }題目 35

題目:文本顏色設(shè)置

#include<cstdio>#include<windows.h>/gov要深入了解得朋友,建議自行檢索相關(guān)資料gov/void textcolor(int color) { HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOutput, color);}int main(){ for (int color = 1;color < 16;color++) { textcolor(color); printf("This is color %d\r\n", color); } textcolor(128 + 15); printf("This is blinking\r\n");}

 
(文/葉之漓)
免責(zé)聲明
本文為葉之漓原創(chuàng)作品?作者: 葉之漓。歡迎轉(zhuǎn)載,轉(zhuǎn)載請(qǐng)注明原文出處:http://nyqrr.cn/kbzx/show-120612.html 。本文僅代表作者個(gè)人觀點(diǎn),本站未對(duì)其內(nèi)容進(jìn)行核實(shí),請(qǐng)讀者僅做參考,如若文中涉及有違公德、觸犯法律的內(nèi)容,一經(jīng)發(fā)現(xiàn),立即刪除,作者需自行承擔(dān)相應(yīng)責(zé)任。涉及到版權(quán)或其他問(wèn)題,請(qǐng)及時(shí)聯(lián)系我們郵件:weilaitui@qq.com。
 

Copyright?2015-2023 粵公網(wǎng)安備 44030702000869號(hào)

粵ICP備16078936號(hào)

微信

關(guān)注
微信

微信二維碼

WAP二維碼

客服

聯(lián)系
客服

聯(lián)系客服:

24在線QQ: 770665880

客服電話: 020-82301567

E_mail郵箱: weilaitui@qq.com

微信公眾號(hào): weishitui

韓瑞 小英 張澤

工作時(shí)間:

周一至周五: 08:00 - 24:00