注册 登录
编程论坛 C++教室

输入一个菱形,两种语句

瑜霏雨 发布于 2017-04-04 17:57, 1425 次点击
哪位大神能告诉我怎么用while和do while分别输入一个菱形?
2 回复
#2
yangfrancis2017-04-07 10:14
你会哪种先输一个,别人自会在你代码基础上帮你改出另一个。我在用手机上网编不了程
#3
yangfrancis2017-04-07 21:49
#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
int main()
{
   
    int y=0,x;
    cout<<"Try Method One:";getch();
    system("cls");
    while(y<7)
    {
        for(x=0;x<7;x++)
            if(abs(x-3)+abs(y-3)<=3) cout<<"*";
            else cout<<" ";
        cout<<endl;
        y++;
    }
    cout<<"Press anykey to continue...";getch();
    system("cls");
    cout<<"Try Method Two:";
    getch();
    system("cls");
    y=0;
    do
    {
        for(x=0;x<7;x++)
            if(abs(x-3)+abs(y-3)<=3) cout<<"*";
            else cout<<" ";
        cout<<endl;
    }while(++y<7);
    return 0;
}
1