for循环打印乘法表:
#include
// for循环打印乘法表
int main(int argc, const char * argv[]) {
//矩形
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
printf("%i * %i = %i\t", j, i, i * j);
}
printf("\n");
}
printf("\n");
//尖尖朝上
for(int i = ; i <= ; i++){
for (int j =; j <= i; j++) {
printf("%i * %i = %i\t", j, i, i * j);
}
printf("\n");
}
printf("\n");
//尖尖朝下
for (int i = ; i <= ; i++) {
for (int j = i; j <= ; j++) {
printf("%i * %i = %i\t", i, j, i * j);
}
printf("\n");
}
return ;
}
/*
输出结果:
1 * 1 = 1 2 * 1 = 2 3 * 1 = 3 4 * 1 = 4 5 * 1 = 5 6 * 1 = 6 7 * 1 = 7 8 * 1 = 8 9 * 1 = 9
1 * 2 = 2 2 * 2 = 4 3 * 2 = 6 4 * 2 = 8 5 * 2 = 10 6 * 2 = 12 7 * 2 = 14 8 * 2 = 16 9 * 2 = 18
1 * 3 = 3 2 * 3 = 6 3 * 3 = 9 4 * 3 = 12 5 * 3 = 15 6 * 3 = 18 7 * 3 = 21 8 * 3 = 24 9 * 3 = 27
1 * 4 = 4 2 * 4 = 8 3 * 4 = 12 4 * 4 = 16 5 * 4 = 20 6 * 4 = 24 7 * 4 = 28 8 * 4 = 32 9 * 4 = 36
1 * 5 = 5 2 * 5 = 10 3 * 5 = 15 4 * 5 = 20 5 * 5 = 25 6 * 5 = 30 7 * 5 = 35 8 * 5 = 40 9 * 5 = 45
1 * 6 = 6 2 * 6 = 12 3 * 6 = 18 4 * 6 = 24 5 * 6 = 30 6 * 6 = 36 7 * 6 = 42 8 * 6 = 48 9 * 6 = 54
1 * 7 = 7 2 * 7 = 14 3 * 7 = 21 4 * 7 = 28 5 * 7 = 35 6 * 7 = 42 7 * 7 = 49 8 * 7 = 56 9 * 7 = 63
1 * 8 = 8 2 * 8 = 16 3 * 8 = 24 4 * 8 = 32 5 * 8 = 40 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64 9 * 8 = 72
1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81
1 * 1 = 1
1 * 2 = 2 2 * 2 = 4
1 * 3 = 3 2 * 3 = 6 3 * 3 = 9
1 * 4 = 4 2 * 4 = 8 3 * 4 = 12 4 * 4 = 16
1 * 5 = 5 2 * 5 = 10 3 * 5 = 15 4 * 5 = 20 5 * 5 = 25
1 * 6 = 6 2 * 6 = 12 3 * 6 = 18 4 * 6 = 24 5 * 6 = 30 6 * 6 = 36
1 * 7 = 7 2 * 7 = 14 3 * 7 = 21 4 * 7 = 28 5 * 7 = 35 6 * 7 = 42 7 * 7 = 49
1 * 8 = 8 2 * 8 = 16 3 * 8 = 24 4 * 8 = 32 5 * 8 = 40 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64
1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81
1 * 1 = 1 1 * 2 = 2 1 * 3 = 3 1 * 4 = 4 1 * 5 = 5 1 * 6 = 6 1 * 7 = 7 1 * 8 = 8 1 * 9 = 9
2 * 2 = 4 2 * 3 = 6 2 * 4 = 8 2 * 5 = 10 2 * 6 = 12 2 * 7 = 14 2 * 8 = 16 2 * 9 = 18
3 * 3 = 9 3 * 4 = 12 3 * 5 = 15 3 * 6 = 18 3 * 7 = 21 3 * 8 = 24 3 * 9 = 27
4 * 4 = 16 4 * 5 = 20 4 * 6 = 24 4 * 7 = 28 4 * 8 = 32 4 * 9 = 36
5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45
6 * 6 = 36 6 * 7 = 42 6 * 8 = 48 6 * 9 = 54
7 * 7 = 49 7 * 8 = 56 7 * 9 = 63
8 * 8 = 64 8 * 9 = 72
9 * 9 = 81
*/
递归替换for循环:
#include
void printfMultiple(int);
void printfMultiple1(int);
void printfMultiple2(int);
void replaceFor(int,int);
int main(int argc, const char * argv[]) {
/*
int i
i 从 1 加到 9
输出 i * 1 ~ 9 的结果
i == 0时退出
*/
int num1 = ;
printfMultiple(num1);
printf("\n");
int num2 = ;
printfMultiple1(num2);
printf("\n");
int num3 = ;
printfMultiple2(num3);
return ;
}
//输出结果: 尖尖朝下
void printfMultiple(int i){
if( == i){
return;
}
else{
//输出 i * 1 到 i * 9 的结果
for (int j = ; j <= i ; j++) {
printf("%i * %i = %i\t", i, j, i * j);
}
printf("\n");
// i 控制 行数 i-- 表示进行下一行的输出
i--;
printfMultiple(i);
}
}
// 如果 i 从 1 开始 i = 10 结束 就尖尖朝上了
void printfMultiple1(int i){
if ( == i) {
return;
}
else{
for (int j = ; j <= i; j++) {
printf("%i * %i = %i\t", j, i, i * j);
}
printf("\n");
i++;
printfMultiple1(i);
}
}
/*用递归替换方法体里的for循环
接收参数 i j
退出条件 j == i + 1
*/
void printfMultiple2(int i){
if ( == i) {
return;
}
else{
replaceFor(i, );
printf("\n");
i++;
printfMultiple2(i);
}
}
//用这个方法替换到原来for循环的位置
void replaceFor(int num1, int num2){
if (num2 == num1 + ) {
return;
}
else{
printf("%i * %i = %i\t", num2, num1, num1 * num2);
num2++;
replaceFor(num1, num2);
}
}
/*
输出结果:
9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81
8 * 1 = 8 8 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 * 6 = 48 8 * 7 = 56 8 * 8 = 64
7 * 1 = 7 7 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35 7 * 6 = 42 7 * 7 = 49
6 * 1 = 6 6 * 2 = 12 6 * 3 = 18 6 * 4 = 24 6 * 5 = 30 6 * 6 = 36
5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25
4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16
3 * 1 = 3 3 * 2 = 6 3 * 3 = 9
2 * 1 = 2 2 * 2 = 4
1 * 1 = 1
1 * 1 = 1
1 * 2 = 2 2 * 2 = 4
1 * 3 = 3 2 * 3 = 6 3 * 3 = 9
1 * 4 = 4 2 * 4 = 8 3 * 4 = 12 4 * 4 = 16
1 * 5 = 5 2 * 5 = 10 3 * 5 = 15 4 * 5 = 20 5 * 5 = 25
1 * 6 = 6 2 * 6 = 12 3 * 6 = 18 4 * 6 = 24 5 * 6 = 30 6 * 6 = 36
1 * 7 = 7 2 * 7 = 14 3 * 7 = 21 4 * 7 = 28 5 * 7 = 35 6 * 7 = 42 7 * 7 = 49
1 * 8 = 8 2 * 8 = 16 3 * 8 = 24 4 * 8 = 32 5 * 8 = 40 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64
1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81
1 * 1 = 1
1 * 2 = 2 2 * 2 = 4
1 * 3 = 3 2 * 3 = 6 3 * 3 = 9
1 * 4 = 4 2 * 4 = 8 3 * 4 = 12 4 * 4 = 16
1 * 5 = 5 2 * 5 = 10 3 * 5 = 15 4 * 5 = 20 5 * 5 = 25
1 * 6 = 6 2 * 6 = 12 3 * 6 = 18 4 * 6 = 24 5 * 6 = 30 6 * 6 = 36
1 * 7 = 7 2 * 7 = 14 3 * 7 = 21 4 * 7 = 28 5 * 7 = 35 6 * 7 = 42 7 * 7 = 49
1 * 8 = 8 2 * 8 = 16 3 * 8 = 24 4 * 8 = 32 5 * 8 = 40 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64
1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81
*/
For循环输出九九乘法表
题:使用For循环输出九九乘法表 解析: 1*1=1 1*2=2 2*2=4 1*3=3 2*3=6 3*3=9 .... 1*9=9 ........ .....9*9=81 可以看做j*i ...
一行python打印乘法表
一行代码打印乘法表 >>> print '\n'.join([' '.join(['%s*%s=%-2s' %(y,x,x*y) for y in range(1,x+1)]) fo ...
for循环实现九九乘法表
javascript基础之打印乘法表
废话不多说,直接上代码!! 代码如下: for(var i =1; i<=9;i++){ for(var j =1; j<=i;j++){ document.write(i+"* ...
day4(分支结构,循环结构,for循环,九九乘法表)
一:复习 ''' 1.变量名命名规范 -- 1.只能由数字.字母 及 _ 组成 -- 2.不能以数字开头 -- 3.不能与系统关键字重名 -- 4._开头有特殊含义 -- 5.__开头__结尾的变量, ...
简单的for循环实现九九乘法表
PHP for 循环 语法 for (init counter; test counter; increment counter) { code to be executed; } 参数: init ...
随机推荐
LeetCode Reverse Vowels of a String
原题链接在这里:https://leetcode.com/problems/reverse-vowels-of-a-string/ 题目: Write a function that takes a ...
JS基础(超级简单)
1 JS基础(超级简单) 1.1 数据类型 1.1.1 基本类型: 1) Number:特别注意:NaN的检测方法:Nan!=NaN;或者使用isNaN方法 2) ...
mysql 自动备份导出到sql
创建一个sh文件 vi mysql_auto.sh写入如下代码 导出单个数据库 /www/wdlinux/mysql/bin/mysqldump -uroot -p123456 database &g ...
getHibernateTemplate()和getSession()的区别
自动生成hibernate配置文件的时候,会在dao层用到getSession()方法来操作数据库记录,但是他还有个方法getHibernateTemplate(),这两个方法究竟有什么区别呢? 1. ...
poj 3487 稳定婚姻
/** 稳定婚姻:男生不停的求婚,女生不停地拒绝 **/ #include #include #include
Docker(十三):OpenStack部署Docker集群
1.介绍 本教程使用Compose.Machine.Swarm工具把WordPress部署在OpenStack上. 本节采用Consul作为Swarm的Discovery Service模块,要利用C ...
对Bitmap的内存优化
在Android应用里,最耗费内存的就是图片资源.而且在Android系统中,读取位图Bitmap时,分给虚拟机中的图片的堆栈大小只有8M,如果超出了,就会出现OutOfMemory异常.所以,对于图 ...
openssh-win64 on windows2016 ssh pub key config
DO NOT follow the official M$ documentation at https://docs.microsoft.com/en-us/windows-server/admin ...
oracle传输表空间相关
1.convert tablespaceconvert tablespace源端库执行:convert tablespace 'TPS_DATA' to platform 'AIX-Based Sys ...
java io系列26之 RandomAccessFile
本文主要介绍 RandomAccessFile. 转载请注明出处:http://www.cnblogs.com/skywang12345/p/io_26.html 更多内容请参考:java io系列0 ...