Mới vẽ được tới h là bó chân đấy;ko thể tìm ra Logic như thế nào mà làm
Mã từ A tới H nè:
/* Tao Hinh tu dau * voi so dua ra */
#include
#include
#include
void hinhvuong(int n) //Hinh A
{
int i,j;
for(i=1;i<=n;i++)
{ for(j=1;j<=n;j++)
cout<<"* ";
cout< }
}
void hinhvuongb(int n)
{
int i,j;
for(i=1;i<=n;i++)
{ for(j=1;j<=n;j++)
if (i==1||i==n||j==1||j==n)
cout<<"* ";
else
cout<<" ";
cout<}
}
void tamgiac(int n)
{
int i,j;
for(i=1;i<=n;i++)
{ for(j=1;j<=i;j++)
cout<<"* ";
cout<}
}
void tamgiacd(int n)
{
int i,j;
for(i=1;i<=n;i++)
{ for(j=1;j<=i;j++)
if (i==1||i==n||j==1||j==i)
cout<<"* ";
else
cout<<" ";
cout<}
}
void tamgiace(int n)
{
int i,j;
for(i=1;i<=n;i++)
{ for(j=i;j<=n;j++)
cout<<"* ";
cout<}
}
void tamgiacf(int n)
{
int i,j;
for(i=1;i<=n;i++)
{ for(j=i;j<=n;j++)
if (i==1||i==n||j==i||j==n)
cout<<"* ";
else
cout<<" ";
cout< }
}
void tamgiacg(int n)
{
int i,j;
for(i=1;i<=n;i++)
{ for(j=1;j<=n;j++)
if ((n-j)>=i)
cout<<" ";
else
cout<<"* ";
cout<}
}
void tamgiach(int n)
{
int i,j;
for(i=1;i<=n;i++)
{ for(j=1;j<=n;j++)
if (j+i==n+1||i==n||j==n)
cout<<"* ";
else
cout<<" ";
cout<}
}
void tamgiaci(int n)
{
int m,t,i,j;
m=n*2-1; t=n-1;
for(i=0;i{
for(j=0;j{
if(j>=t&&j<=m-t-1||i==n-1)
printf("*");
else
printf(" ");
}
printf("\n");
t--;
}
}
void tamgiacj(int n)
{
int i,j,m,t;
m=n*2-1; t=n-1;
for(i=0;i{
for(j=0;j {
if(j==t||j==m-t-1||i==n-1)
printf("*");
else
printf(" ");
}
printf("\n");
t--;
}
}
void main()
{int n;
cout<<"Nhap n: ";
cin>>n;
hinhvuong(n);
cout<<"\n";
hinhvuongb(n);
cout<<"\n";
tamgiac(n);
cout<<"\n";
tamgiacd(n);
cout<<"\n";
tamgiace(n);
cout<<"\n";
tamgiacf(n);
cout<<"\n";
tamgiacg(n);
cout<<"\n";
tamgiach(n);
cout<<"\n";
tamgiaci(n);
cout<<"\n";
tamgiacj(n);
cout<<"\n";
getche();
}