c语言中绘制三角形
1、
#include <stdio.h>
int main(void)
{
int i, j, len;
puts("please input the len.");
printf("len = "); scanf("%d", &len);
for (i = 1; i <= len; i ++ )
{
for (j = 1; j <= i; j ++ )
{
putchar('*');
}
putchar('\n');
}
return 0;
}
2、
#include <stdio.h>
int main(void)
{
int i, j, len;
puts("please input the len.");
printf("len = "); scanf("%d", &len);
for (i = 1; i <= len; i ++)
{
for (j = 1; j <= len; j ++)
{
if (j > (len - i))
putchar('*');
else
putchar(' ');
}
putchar('\n');
}
return 0;
}
↓
#include <stdio.h>
int main(void)
{
int i, j, len;
puts("please input an integer.");
printf("len = "); scanf("%d", &len);
for (i = 1; i <= len; i ++ )
{
for (j = 1; j <= (len -i); j ++ )
{
putchar(' ');
}
for (j = 1; j <= i; j ++)
{
putchar('*');
}
putchar('\n');
}
return 0;
}
3、
#include <stdio.h>
int main(void)
{
int i, j, len;
puts("please input the len.");
printf("len = "); scanf("%d", &len);
for (i = 1; i <= len; i ++ )
{
for (j = 1; j <= len; j ++ )
{
if (j <= (len - i + 1))
{
putchar('*');
}
}
putchar('\n');
}
return 0;
}
↓
#include <stdio.h>
int main(void)
{
int i, j, len;
puts("please input the len.");
printf("len = "); scanf("%d", &len);
for (i = 1; i <= len; i ++ )
{
for (j = 1; j <= (len - i + 1); j ++ )
{
putchar('*');
}
putchar('\n');
}
return 0;
}
4、
#include <stdio.h>
int main(void)
{
int i, j, len;
puts("please input the len.");
printf("len = "); scanf("%d", &len);
for (i = 1; i <= len; i ++)
{
for (j = 1; j <= len; j ++)
{
if (j > (i - 1))
putchar('*');
else
putchar(' ');
}
putchar('\n');
}
return 0;
}
↓
#include <stdio.h>
int main(void)
{
int i, j, len;
puts("please input the len.");
printf("len = "); scanf("%d", &len);
for (i = 1; i <= len; i ++ )
{
for (j = 1; j < i; j ++ )
{
putchar(' ');
}
for (j = 1; j <= (len + 1 - i); j ++)
{
putchar('*');
}
putchar('\n');
}
return 0;
}