NO23.【婳骨】の乘法表系统

题目

原题:
使用程序打印九九乘法表
样例输出:
1 * 1 = 1
1 * 2 = 2 2 * 2 = 4
1 * 3 = 3 2 * 3 = 6 3 * 3 = 9
….

代码

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>

#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:4996)

void In(double* a);	//对输入数据进行判断
int main()
{
	double _num;	//用于接收输入的数字
	int num;	//最高为num×num
	int i, j;	//用于循环
	int result;	//运算结果
	int choice;	//检验是否退出
	system("title 【婳骨】の乘法表系统");
	while (1) {
		printf("欢迎来到【婳骨】の乘法表系统\n请输入需要几几乘法表?\n");
		while (1) {
			In(&_num);
			num = (int)_num;
			if (num < 1) {
				printf("输入范围不对啦,请重新输入!\n");
			}
			else break;
		}
		for (i = 1; i < num + 1; i++) {
			for (j = 1; j < i + 1; j++) {
				result = i * j;
				printf("%d × %d = %d", i, j, result);
				printf("\t");
			}
			printf("\n");
		}
		printf("是否重新运行本程序?如需重新运行请输入0,否则按任意键退出\n");
		choice = getch();
		if (choice == '0') {
			system("cls");
		}
		else break;
	}
	printf("谢谢使用!推荐您背好乘法表呢亲~");
	system("pause");
	return 0;
}
void In(double* a)	//对输入数据进行判断
{
	do
	{
		if (scanf_s("%lf", a) == 1)
		{
			break;
		}
		char choice;
		while ((choice = getchar()) != '\n' && choice != EOF);
		printf("输入的不是数字!\n");
	} while (scanf_s("%lf", a) != 1);
}

部分运行结果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值