《c语言教程》

下载本书

添加书签

c语言教程- 第32节


按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
  getch();

 
 
  。:。:经典c程序100例3140:。:。 
  

    经典c程序100例3140

【程序31】
题目:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续
   判断第二个字母。
1。程序分析:用情况语句比较好,如果第一个字母一样,则判断用情况语句或if语句判断第二个字母。
2。程序源代码:
#include 〃stdio。h〃
#include 〃conio。h〃
void main()

  char letter;
  printf(〃please input the first letter of somedayn〃);
  while((letter=getch())!='Y')/*当所按字母为Y时才结束*/
  {
    switch (letter)
    {
      case 'S':printf(〃please input second lettern〃);
      if((letter=getch())'a')
        printf(〃saturdayn〃);
        else if ((letter=getch())'u')
          printf(〃sundayn〃);
          else printf(〃data errorn〃);
      break;
      case 'F':printf(〃fridayn〃);break;
      case 'M':printf(〃mondayn〃);break;
      case 'T':printf(〃please input second lettern〃);
      if((letter=getch())'u')
        printf(〃tuesdayn〃);
        else if ((letter=getch())'h')
          printf(〃thursdayn〃);
        else printf(〃data errorn〃);
      break;
      case 'W':printf(〃wednesdayn〃);break;
      default: printf(〃data errorn〃);
    }
  }
  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 %drn〃; color);
    cprintf(〃Press any key to continuern〃);
    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 1n〃);
  textbackground(3);
  gotoxy(20; 10);
  cprintf(〃Output at row 10 column 20n〃);
  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 
小提示:按 回车 [Enter] 键 返回书目,按 ← 键 返回上一页, 按 → 键 进入下一页。 赞一下 添加书签加入书架