求写菱形的代码
求菱形的完整代码, 用FOR 来写, m为行数,按以下的思路来写for(i=1;i<=2*m-1;i++)
{
for(j=1;j<=fabs(m-i);j++)
printf(" ");
.......
}
[[it] 本帖最后由 ypu 于 2008-10-15 21:19 编辑 [/it]]
#include<stdio.h> #include<math.h> int main(void) { int i,j,k,n; do { printf("input n:\n"); scanf("%d",&n); if(n>23||n%2==0) printf("error\n"); }while(n>23||n%2==0); n/=2; k=n+1; for(i=-n;i<=n;i++) { for(j=0;j<abs(i);j++) printf(" "); for(j=0;j<(k-abs(i))*2-1;j++) printf("*"); printf("\n"); } getch(); }
#include <stdio.h> main(i) { i<30&& ( i%6<5&& ( printf(i%6>4-i/6?"*":"_"), main(i+1), printf(i%6>=4-i/6?"*":"_") ), i%6==1&& ( printf(i%6>4-i/6?"*":"_"), printf("\n"), main(i+6), i+=30 ) ), i>=32&& ( i%6<5&& ( printf(i%6>10-i/6?"*":"_"), main(i+1), printf(i%6>=10-i/6?"*":"_") ), i%6==1&& ( printf(i%6>10-i/6?"*":"_"), printf("\n") ) ); }