c - 是否可以使用循环输出数字键盘的模式?
问题描述
几个月前我刚开始学习 C(一般编码)。今天早些时候,当我在课堂上时,我看着小键盘,想知道我是否能够使用 C 中的嵌套循环来复制该模式。
7 8 9
4 5 6
1 2 3 // This pattern.
我尝试自己做一点,主要使用 for 循环。谢谢你的帮助。
#include<stdio.h>
int main()
{
int row, col, i;
printf("Up to what integer? ");
scanf("%d", &row);
for(i=1; i<=row; i++)
{
for(col=1; col<=10; col++)
{
printf(" %d ", i*col);
}
printf("\n");
}
}
编辑:添加了补充代码。像这样,除了打印 3 行和 3 列。
解决方案
以下是您的操作方法:
for(int i = 0; i < 3; ++i){
for(int j = 3; j > 0; --j)
printf("%d ", (10 - j) - i * 3);
printf("\n");
}
推荐阅读
- python - 在运行 Python 进程中缓存 Django 相关字段
- php - Sum Pivot Table 的列 Laravel
- java - 未能执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1
- apache-spark - 如何防止针对 CSV 胶水目录源的火花查询包含标题?
- swagger - 将 Swagger Api 转换为 Asciidoc
- javascript - 如何在 ES6/React 中将小写和下划线转换为正确的大小写和空格
- node.js - 评估函数“floor”时出错:参数必须是数字
- tampermonkey - 如何删除或隐藏每个
和 Tampermonkey 的边界底部的东西?
- android - TextField 在保存到缓存时删除最后一个字母
- reactjs - 可以通过另一个组件中的 onClick 侦听器调用 React JS 类吗?