Write the program exp3_2.c, first define a function, its prototype is: void DrawPic(int n, char c); the function is: print an isosceles triangle composed of characters c in n lines. Three calls are given in the main function, and 7 lines of '*',

#include<stdio.h>
void DrawTriangle(int n,char c);
int main()
{
    
    
    DrawTriangle(7,'*');
    printf("\n");
    DrawTriangle(11,'@');
    printf("\n");
    DrawTriangle(20,'$');
    return 0;
}
void DrawTriangle(int n,char c)
{
    
    
    int i,j;
    for(i=1;i<=n;i++)
    {
    
    
        printf("                                             ");
        for(j=1;j<=n-i;j++)
            printf(" ");
        for(j=1;j<=2*i-1;j++)
            printf("%c",c);
        printf("\n");
    }
    return;
}

Guess you like

Origin blog.csdn.net/weixin_52374973/article/details/110001562