创建列和行;询问用户想要输出的行数,然后询问显示
creating columns and rows; asking for the number of lines the user wants to output then the display
//libraries
#include <iostream>
//global constants
//no functioning prototypes
using namespace std;
int main(){
//Define variables
int n; // Number of rows
int i; // Row count in for loop
int k; // Output for loop
// Have user input n
cout << "Enter number of rows: ";
cin >> n;
// Complete for loop
for (i = 1; i <= n + 1; i++){
for (k = 1; k < i; k++){
cout << k%10;
}
cout << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
我正在尝试创建一个与此类似的代码,除了而不是放
1
12
123
1234
12345
我需要它看起来像
1
2
3
4
5
其中结束数字是列数是输入的数字和空格而不是以前的数字
您只需要替换此行:
cout << k%10;
对于此行:
if (k<i-1) cout << ' '; else cout << k%10;
如果我们在当前行的最后一个位置,这将打印数字,如果我们不在,则会打印一个空格。
#include "stdafx.h"
#include"iostream"
#include"conio.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int a=1;
int n;
cout<<"enter the lenght of the numbers";
cin>>n;
for (int i=1;i<=n;i++)
{
{for (int j=1;j<=n;j++)
if (j==a)
cout<<j;
else cout<<" ";
}
cout<<endl;
a=a+1;
}
_getch();
}
相关文章:
- 如何存储用户输入的所有数据,然后在他们想要查看所有数据时显示它们
- 从文本文件中读取并输入到数组结构中,然后显示读取的数据C++
- Gtkmm - 关闭窗口然后显示另一个窗口的正确方法
- 如何存储多个用户输入,然后以C++显示它们
- 如何从文本文件中获取值,然后用它们执行一些计算(例如乘以并显示它们)?
- 将25个甚至整数存储到一个名为intlist的整数阵列中,然后在屏幕上显示数组,并在屏幕上显示名为fivintegers
- 根据标准对结构向量进行排序,然后显示结果
- 显示然后删除链接列表C
- 我如何调用我的3个数据成员中每个人的设置方法,然后显示由我的设置方法设置的值
- 如何增加几个月循环.然后显示
- 如何使用我的 if-else 语句根据用户权重的输入执行特定操作,然后将其显示到控制台?
- c++将var从一个函数传递到另一个函数,然后在主函数中显示结果
- MFC:在 CRichEditCtrl 中突出显示一条线一段时间,然后恢复
- C++,使用 stack.h 读取一个字符串,然后反向显示它
- 图像在隐藏时消失,然后重新显示ListView
- 对输入'age'名称进行排序,然后显示结果
- 如何附加到相邻的十六进制值,然后显示
- 尝试在单击按钮时捕获编辑框中的文本,然后显示到另一个编辑框
- C++如何将数组传递给函数,然后调用它来显示数组的值
- 如何在mousepressEvent()函数中显示像素坐标,然后如何在每次单击鼠标时在paintGL()函数中将其使用