如何在C++中使用星号(*)绘制V字母形状

How to Draw V Letter Shape Using Asterisk(*) in C++

本文关键字:绘制 C++      更新时间:2023-10-16

我想在C++中画一个字符 V。我不知道该怎么做才能获得所需的结果。

#include <iostream.h>
using namespace std;
int main()
{
int i, j;
for()
{
    for()
    {
      if(i == j)
      {
        cout << "*";
      }
      else
      {
        cout << " ";
      }
}
cout<< endl;
return 0;
}
int main()
{
  std::cout << "*      *n"
               " *    *n"
               "  *  *n"
               "   **n"
}

我不是C++的忠实粉丝,但我试图给出逻辑

#include <iostream.h>
using namespace std;
int main() {
    int n; //height of the Char V
    int i, j;
    #char s=""; //i know only to adding string if u add s as string 
    for(int x = 1, y = n ; x <= y ; x++, y--) {
        cout << s;
        cout << "*";
        for(int t = 1 ; t < t ; t++) {
            cout << "";
        }
        cout << "*";
        s=s+"";
    }
    cout << endl;
    return 0;
}
private static void drawPattern(int height) {
    // TODO Auto-generated method stub
    int end=height * 2;
    int j=0;
    for ( int start=0;start<height;start++,end--) {
        for ( j=0;j<start;j++){
            System.out.print(" ");  
        }   
        System.out.print("*");
        for ( ;j<end;j++) {
            System.out.print(" ");
        }
        System.out.println("*");
    }
}

JAVA中的一个脏实现,尝试移植到C++,高度可以由用户输入