千鋒教育-做有情懷、有良心、有品質的職業教育機構

手機站
千鋒教育

千鋒學習站 | 隨時隨地免費學

千鋒教育

掃一掃進入千鋒手機站

領取全套視頻
千鋒教育

關注千鋒學習站小程序
隨時隨地免費學習課程

當前位置:首頁  >  技術干貨  > c語言經典練習題100道(七)

c語言經典練習題100道(七)

來源:千鋒教育
發布人:syq
時間: 2022-07-29 17:23:00 1659086580

  【程序31】 題目:請輸入星期幾的第一個字母來判斷一下是星期幾,如果第一個字母一樣,則繼續判斷第二個字母。

c語言經典練習題

  1.程序分析:用情況語句比較好,如果第一個字母一樣,則判斷用情況語句或if語句判斷第二個字母。

  2.程序源代碼:

#include "stdio.h"

#include "conio.h"

void main(){

  char letter;

  printf("please input the first letter of someday\n");

  while((letter=getch())!='Y')/*當所按字母為Y時才結束*/

  {

    switch (letter)

    {

      case 'S':printf("please input second letter\n");

      if((letter=getch())=='a')

        printf("saturday\n");

        else if ((letter=getch())=='u')

          printf("sunday\n");

          else printf("data error\n");

      break;

      case 'F':printf("friday\n");break;

      case 'M':printf("monday\n");break;

      case 'T':printf("please input second letter\n");

      if((letter=getch())=='u')

        printf("tuesday\n");

        else if ((letter=getch())=='h')

          printf("thursday\n");

        else printf("data error\n");

      break;

      case 'W':printf("wednesday\n");break;

      default: printf("data error\n");

    }

  }

  getch();

}

  ——————————————————————————————————————

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

  1.程序分析:

  2.程序源代碼:

#include "conio.h"

#include "stdio.h"

void main(void){

  int color;

  for (color = 0; color < 8; color++)

  { 

    textbackground(color);/*設置文本的背景顏色*/

    cprintf("This is color %d\r\n", color);

    cprintf("Press any key to continue\r\n");

    getch();/*輸入字符看不見*/

  }

}

  ——————————————————————————————————————

  【程序33】 題目:學習gotoxy()與clrscr()函數

  1.程序分析:

  2.程序源代碼:

#include "conio.h"

#include "stdio.h"void main(void){

  clrscr();/*清屏函數*/

  textbackground(2);

  gotoxy(1, 5);/*定位函數*/

  cprintf("Output at row 5 column 1\n");

  textbackground(3);

  gotoxy(20, 10);

  cprintf("Output at row 10 column 20\n");

  getch();

}

  ——————————————————————————————————————

  【程序34】 題目:練習函數調用

  1. 程序分析:

  2.程序源代碼:

#include "stdio.h"

#include "conio.h"

void hello_world(void){

  printf("Hello, world!\n");}void three_hellos(void){

  int counter;

  for (counter = 1; counter <= 3; counter++)

    hello_world();/*調用此函數*/}void main(void){

  three_hellos();/*調用此函數*/

  getch();

}

  ——————————————————————————————————————

  【程序35】 題目:文本顏色設置

  1.程序分析:

  2.程序源代碼:

#include "stdio.h"

#include "conio.h"

void main(void){

  int color;

  for (color = 1; color < 16; color++)

  {

    textcolor(color);/*設置文本顏色*/

    cprintf("This is color %d\r\n", color);

  }

  textcolor(128 + 15);

  cprintf("This is blinking\r\n");

  getch();

}

  ——————————————————————————————————————

  更多關于“物聯網培訓”的問題,歡迎咨詢千鋒教育在線名師。千鋒教育多年辦學,課程大綱緊跟企業需求,更科學更嚴謹,每年培養泛IT人才近2萬人。不論你是零基礎還是想提升,都可以找到適合的班型,千鋒教育隨時歡迎你來試聽。

tags:
聲明:本站稿件版權均屬千鋒教育所有,未經許可不得擅自轉載。
10年以上業內強師集結,手把手帶你蛻變精英
請您保持通訊暢通,專屬學習老師24小時內將與您1V1溝通
免費領取
今日已有369人領取成功
劉同學 138****2860 剛剛成功領取
王同學 131****2015 剛剛成功領取
張同學 133****4652 剛剛成功領取
李同學 135****8607 剛剛成功領取
楊同學 132****5667 剛剛成功領取
岳同學 134****6652 剛剛成功領取
梁同學 157****2950 剛剛成功領取
劉同學 189****1015 剛剛成功領取
張同學 155****4678 剛剛成功領取
鄒同學 139****2907 剛剛成功領取
董同學 138****2867 剛剛成功領取
周同學 136****3602 剛剛成功領取
相關推薦HOT
久久亚洲中文字幕精品一区四,亚洲日本另类欧美一区二区,久久久久久久这里只有免费费精品,高清国产激情视频在线观看
日本中文字幕aⅴ高清看片 亚洲欧美性综合在线 | 五月天AV免费在线观看 | 中文有码视频在线播放免费 | 日韩精品亚洲国产中文一区蜜芽 | 日本在线精品视频观看 | 亚洲有码在线观看 |