c++ 用循环语句编程打印如下图案
stststststststststs
ststststststststs
stststststststs
ststststststs
stststststs
ststststs
stststs
ststs
sts
s
很高兴回答你的问题,根据我对你给出图形的理解,写咐做岁了下面这段代码:
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("第一个图形");
test1(8,17);
System.out.println("第二个图形");
test(9);
}
public static void test1(int rownum,int colnum){
for(int i=0;i<rownum;i++){
for(int m=0;m<i;m++){
System.out.print(" ");
}
for(int j=colnum-i;j>0;j--){
System.out.print("# ");
}
System.out.println();
}
}
public static void test(int num){
System.out.print("*");
for(int i=1;i<=num;i++){
System.out.print("\t"+i);
}
System.out.println();
for(int i=1; i<=num;i++){
for(int j=1;j<=i;j++){
if(j==1){
System.out.print(i);
}
System.out.print("\t"+(i*j));
}
System.out.println();
}
}
}
输出结果:
第一个图形
# # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # #
# # # # # # # # # # # # # #
# # # # # # # # # # # # #
# # # # # # # # # # # #
# # # # # # # # # # #
# # # # # # # # # #
第二个图形
* 1 2 3 4 5 6 7 8 9
1 1
2 2 4
3 3 6 9
4 4 8 12 16
5 5 10 15 20 25
6 6 12 18 24 30 36
7 7 14 21 28 35 42 49
8 8 16 24 32 40 48 56 64
9 9 18 27 36 45 54 63 72 81
如果有问题衡睁或疑胡散问,请Hi我,谢谢!
凭直觉……我认为你本意是要输出一个倒三角形,但是前面的空格被系统余拿默认删掉了……
如果我的直觉对了乱改的话,你可以竖陪搭参考以下程序:
#include <iostream>
using namespace std;
int main()
{
char s = 's';
char t = 't';
int n = 10;
for (int row=1;row<=n;row++)
{
for (int blank=0;blank<row-1;blank++)
cout << " ";
cout << s;
for (int col=1;col<=n-row;col++)
cout << t << s;
cout << '\n';
}
}
钱能汪悄亩的困森书,嘿嘿
vs2008编译通过
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
for(int j=1;j<12;j++){
cout<<setw(j+1)<<setfill(' ')<<" ";
for(int i=1;i<(24-2*j);i++)
if (i%2) cout<<"S";
else cout<<"T";
cout<运枯<endl;}}
/亮唯/#include "stdafx.h"//如果使好梁用vs编译,需要加上这行代码友键运。
#include "iostream"
using namespace std;
int main(int argc, char* argv[])
{
int n;
int temp;
n=9;
temp=n;
for(int i=0;i<=n;i++)
{
cout<<"s";
for(int j=0;j<temp;j++)
{
cout<<"ts";
}
temp--;
cout<<endl;
}
return 0;
}
#include<iostream>
using namespace std;
void main()
{
char a[2]={'s','洞蠢t'};
for(int i=0;i<10;i++)
{
for(int j=0;j<10-i;j++)
{
if(j%2==0)
cout<<a[0];
else
cout<<a[1];
}
cout<<endl;
}
}
引纳卖陪用上面的,呵呵配模