目录

老狼几点了!

 爱心

行走的小人 

猜数字游戏 


老狼几点了!

#include <bits/stdc++.h>
using namespace std;
int main() {
	int i;
	for(i=1; i<=12; i++) {
       //循环1~12。
		cout<<"老狼老狼几点钟?"<<i<<"点钟。"<<endl;
	}
	cout<<"狼来了,快跑!";
	return 0;
}

 爱心

#include <bits/stdc++.h>
using namespace std;
int main() {
	float x,y,a;
	for(y=1.5; y>-1.5; y-=0.1) {
		for(x=-1.5; x<1.5; x+=0.05) {
			a=x*x+y*y-1;
			putchar(a*a*a-x*x*y*y*y<=0.0?'@':' ');
		}
		system("color 0c");
		putchar('\n');
	}
	return 0;
}


行走的小人 

#include <bits/stdc++.h>
#include<windows.h> 
using namespace std;
int main(){
	for(int i=0;i<=80;i++){//循环小人行走的步数
		for(int j=0;j<=i;j++){
			cout<<' ';
		}
		cout<<" o "<<endl;//输出头部
		for(int j=0;j<=i;j++){
			cout<<' ';
		}
		cout<<"<H>"<<endl;//输出身体
		for(int j=0;j<=i;j++){
			cout<<' ';
		}
		if(i%2==0){
			cout<<"I I";
		}else{
			cout<<"\\ \\";
		}
	Sleep(100);
		system("cls");
	} 
}

猜数字游戏 

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
//void menu() { //菜单函数
//	printf("|------------------- 1.开始游戏 -----------------|\n");
//	printf("|------------------- 0.退出游戏 -----------------|\n");
//}
void game() { //游戏函数
	int i = 0;
	int ret = rand()%100+1 ;//生成随机数
	printf("请猜数字\n");
	while (1) { //while循环,如果猜对跳出来
		scanf("%d", &i);
		if (i < ret) {
			printf("猜小了!\n");
		} else if (i>ret) {
			printf("猜大了!\n");
		} else {
			printf("恭喜你!!猜对了!\n");
			break;
		}
	}
}
int main() { 
	srand((unsigned int)time(NULL));//随机数生成
	int input = 6;
	printf("猜数字,1--100之间\n");
	//do...while循环
	do {
	//	menu();//菜单函数
		printf("请选择数字:>");
		scanf("%d", &input);
		switch (input) {
			case 1:
				game();//游戏函数
				break;
			case 0:
				printf("已退出游戏\n");
				break;
			default:
				printf("输入错误,请重新输入\n");
				break;
		}
	} while (input);
	return 0;
}

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐