C语言 百炼成钢11

时间:2023-03-10 04:23:51
C语言 百炼成钢11
//题目31:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续
//判断第二个字母。 #define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<math.h> //分析:通过输入的字母判定星期几,可以使用if()else void main(){
char str[] = { };
scanf("%s",str);
switch ((int)str[])
{
case :
//f
printf("\n今天是星期五");
break;
case :
//m
printf("\n今天是星期一");
break;
case :
//s
if (str[]==)
{
printf("\n今天是星期六");
}
else{
printf("\n今天是星期日");
}
break;
case :
//t
if (str[] == )
{
printf("\n今天是星期二");
}
else{
printf("\n今天是星期四");
}
break;
case :
//w
printf("\n今天是星期三");
break;
default:
break;
}
system("pause");
}

C语言 百炼成钢11

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

C语言 百炼成钢11

//题目33:求100之内的素数 

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
//分析:写一个函数,判断该数是否是素数 int sushu(int num){
int temp = (int)sqrt(num + );
for (int i = ; i <= temp; i++)
{
if (num%i==)
{
return ;
}
}
return ;
} void main(){
for (int i = ; i < ; i++)
{
if (i==||i==||i==||i==)
{
printf("%d\n", i);
}
else{
if (sushu(i))
{
printf("%d\n", i);
}
}
}
system("pause");
}

C语言 百炼成钢11