博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C语言 百炼成钢11
阅读量:4365 次
发布时间:2019-06-07

本文共 2229 字,大约阅读时间需要 7 分钟。

//题目31:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续//判断第二个字母。#define _CRT_SECURE_NO_WARNINGS#include
#include
#include
//分析:通过输入的字母判定星期几,可以使用if()elsevoid main(){ char str[7] = { 0 }; scanf("%s",str); switch ((int)str[0]) { case 102: //f printf("\n今天是星期五"); break; case 109: //m printf("\n今天是星期一"); break; case 115: //s if (str[1]==97) { printf("\n今天是星期六"); } else{ printf("\n今天是星期日"); } break; case 116: //t if (str[2] == 101) { printf("\n今天是星期二"); } else{ printf("\n今天是星期四"); } break; case 119: //w printf("\n今天是星期三"); break; default: break; } system("pause");}

 

 

 

//题目32:Press any key to change color, do you want to try it. Please hurry up!#define _CRT_SECURE_NO_WARNINGS#include
#include
#include
#include
#include
//分析:cmd指令color的值有2个十六进制构成,范围是0-f,Press any key说明按下任意键变色,借助getchar()函数,//函数名:kbhit()功能及返回值: 检查当前是否有键盘输入,若有则返回一个非0值,否则返回0;用 法:int _kbhit(void);其头文件是conio.hvoid main(){ //定义时间类型 time_t ts; //定义随机数种子 srand((unsigned int)time(&ts)); //定义cmd中color的值 char strcolor[30] = { 0 }; while (1){ getchar(); sprintf(strcolor, "color %x%x", (int)(rand() % 16), (int)(rand() % 16)); system(strcolor); } system("pause");}

 

 

//题目33:求100之内的素数 #define _CRT_SECURE_NO_WARNINGS#include
#include
#include
//分析:写一个函数,判断该数是否是素数int sushu(int num){ int temp = (int)sqrt(num + 1); for (int i = 2; i <= temp; i++) { if (num%i==0) { return 0; } } return 1;}void main(){ for (int i = 0; i < 100; i++) { if (i==0||i==1||i==2||i==3) { printf("%d\n", i); } else{ if (sushu(i)) { printf("%d\n", i); } } } system("pause");}

 

转载于:https://www.cnblogs.com/zhanggaofeng/p/5152685.html

你可能感兴趣的文章
结构化日志:出错时你最想要的好朋友
查看>>
Git常用命令总结
查看>>
[算法练习]Excel Sheet Column Title
查看>>
【原创】MapReduce编程系列之表连接
查看>>
IOS开发之Swift学习笔记
查看>>
【Java基础】用LinkedList实现一个简单栈的功能
查看>>
线段树C-A Simple Problem with Integers(树懒线段树)
查看>>
Ferguson游戏
查看>>
PHPExcel
查看>>
create your own github repository and build link to your local project
查看>>
Leetcode-Convert Sorted Array to BST
查看>>
form表单,submit,ajax提交
查看>>
三大平衡树(Treap + Splay + SBT)总结+模板
查看>>
关于数据库名、实例名
查看>>
多线程不安全的函数列表
查看>>
Codeforces Round #318 (Div. 2) B Bear and Three Musketeers (暴力)
查看>>
SVN+AnkhSVN端配置
查看>>
mysql慢查询工具
查看>>
socket代码
查看>>
HTML5 之 简单汇总
查看>>