2018年4月29日 星期日

c++ 直角三角形 米字

#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
cout << "Input the isosceles triangle's cathetus:  ";  
int ca;
cin >> ca;
//isosceles triangle
for(int i=1;i<=ca;i++)
{
for(int j=1;j<=i;j++)
{
cout<<"*";
}
cout<<endl;
}
system("pause");
return 0;
}






#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
cout << "Input the length: ";
int ca;
cin >> ca;
//the triangle
for(int i=ca;i>0;i--)//control the amount of *
{
for(int j=1;j<=i;j++)//control the row
{
cout<<"*";
}
cout<<endl;
}
system("pause");
return 0;
}


#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
cout << "input the length: ";
int ca;
cin >> ca;
//triangle
for(int i=1;i<=ca;i++)//控制星星數 
{
for(int j=1;j<=ca;j++)//控制行數 
{
if( j<=(ca-i) )
{
cout << " ";
}
else
{
cout << "*";
}
}
cout <<endl;
}

}

















#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
cout << "Input the length: ";
int ca;
cin >> ca;
//triangle
for(int i=1;i<=ca;i++)
{
for(int j=1;j<=ca;j++)//控制行數 
{
if(j>=i)
{
cout << "*";
}
else
{
cout << " ";
}
}
cout <<endl;

system("pause");
return 0;




1 則留言: