如何仅使用2个变量创建Floyd的三角形?
我正在使用这个逻辑,但它使用3个变量,但我只想用2创建它。
for(i=0;i<5;i++)
{
for(j=0;j<i;j++)
{
cout<<k;
k++;
}
}
答案 0 :(得分:0)
FLOYD的三角形模式
#include <iostream>
using namespace std;
int main(){
int i=1,j=1,n;
cout<<"input the value \"n\" upto which FLOYD's triangle needed to print \n"
cin>>n;
while(i<=n){ //here we use only two variable that is "i" and "j";
cout<< i <<" ";//if you are confused with pattern then comment these statement and use below statement.
//cout<<"* ";
if(i>=j*(j+1)/2){
cout<<"\n";
j++;
}
i++;
}
return 0;
}