我想在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;
}
答案 0 :(得分:1)
int main()
{
std::cout << "* *\n"
" * *\n"
" * *\n"
" **\n"
}
答案 1 :(得分:0)
我不是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;
}
答案 2 :(得分: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 ++,高度可以是用户输入