当前位置:编程学习 > C/C++ >>

问题一百四十二:空心三角形

PS:

输出结果为这样,系统才接受:

X 2
 X
XXX
X 2
******     //空行
 X

XXX

 

 

 


[plain] #include<stdio.h> 
 
int main() 

        int  n; 
        int  i; 
        int  j; 
        int  flag=0; 
        char ch; 
         
        while((ch=getchar())!='@') 
        { 
            scanf("%d",&n); 
            getchar(); 
            if(flag) 
            { 
                 printf("\n"); 
            } 
             for(i=1; i<=n; i++) 
             { 
                for(j=1; j<=2*n; j++) 
                {  
                   if(i<n) 
                   { 
                       if(j==n-i+1 || j==n+i-1) 
                       { 
                           printf("%c", ch); 
                       } 
                       else if(j<n+i-1) 
                       { 
                           printf(" "); 
                       } 
                   } 
                   else  
                   { 
                       if(j<=n+i-1) 
                       { 
                           printf("%c", ch); 
                       } 
                   } 
                } 
                printf("\n"); 
             }    
             flag++; 
        } 
 
        return 0; 

补充:软件开发 , C语言 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,