1.打印直角三角形
?
#include<stdio.h>
int main()
{
?? ?char a;
?? ?int n;
?? ?scanf("%c %d", &a, &n);//輸入一個字符 ,打印的行數(shù)
?? ?for (int i = 1; i <= n; i++)
?? ?{
?? ??? ?for (int j = 0; j < i; j++)
?? ??? ??? ?printf("%c", a);
?? ??? ?printf("\n");
?? ?}
}
?
運行結果:?
?2.打印等邊三角形
#include<stdio.h>
int main()
{
char ch;
int i;
int n;
scanf("%c %d", &ch,&n);//打印的字符,以及行數(shù)
for (i = 0; i < n; i++)
{
for (int j = n; j > i; j--)
printf(" ");
for (int x = 0; x < 2*i-1; x++)
printf("%c", ch);
printf("\n");
}
}
結果:
?文章來源地址http://www.zghlxwxcb.cn/news/detail-744594.html
3.打印等腰三角形
#include<stdio.h>
int main()
{
int n;
char a;
scanf("%c %d", &a, &n);//輸入打印的字符,以及行數(shù)為n*2
for (int i = 1; i <= n ; i++)
{
for (int j = 1; j <= 2 * i - 1; j++)
printf("%c", a);
puts("");
}
printf("\b");
for (int i = n - 1; i >= 1; i--) {
for (int j = 1; j <= 2 * i - 1; j++)
printf("%c", a);
puts("");
}
}
結果如下:文章來源:http://www.zghlxwxcb.cn/news/detail-744594.html
?
到了這里,關于C語言 打印圖形(三角形)的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!