【20171015】C语言每日一练

【程序31】
题目:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母。

#include <stdio.h>

int main(int argc, char* argv[])
{
    char a;
    char b;
    printf("请输入:");
    scanf("%c",&a);
    switch(a){

    case('m'):
        printf("monday");
        break;
    case('t'):
        printf("请继续输入:");
        scanf("%c",&b);
        if((b=getchar()) =='u')
        {
            printf("tuesday");
            break;
        }
        else
        {
            printf("thursday");
            break;
        }

    case('w'):
        printf("wednesday");
        break;
    case('f'):
        printf("friday");
        break;
    case('s'):
        printf("请继续输入:");
        scanf("%c",&b);//这里有个疑问,为什么把这句注释掉之后,程序就直接执行else
        if((b=getchar()) == 'a')
            printf("saturday");
        else
            printf("sunday");
        break;
    default:
        printf("Data error");

    }
}

这里写图片描述

以下程序VC++6.0控制台都无法实现,所以只能贴一下代码了
【程序32】
题目:Press any key to change color, do you want to try it. Please hurry up!

#include <conio.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>
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");
}

【程序35】
题目:文本颜色设置

1.程序分析:
2.程序源代码:
#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");
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值