C语言两个fo循环打印菱形.docVIP

  • 7
  • 0
  • 约 5页
  • 2016-10-15 发布于贵州
  • 举报
C语言两个fo循环打印菱形

C语言两个for循环打印菱形   输入数字,打印菱形。   这是一道编程题,更是一道数学题。平常会以for循环打印输出,仔细想想,用两个for完全可以实现。   以数字5为例:   方法一(以循环为主打印)   #include stdio.h   void print(int n)   {   int i,j;   for(i=1; i=n; i++)   {   for(j=1; j=n-i; j++)   {   printf( );   }   for(j=n-i+1; jn+i; j++)   {   printf(*);   }   printf(\n);   }   for(i=n-1; i=1; i--)   {   for(j=1; j=(n-i); j++)   {   printf( );   }   for(j=n-i+1; jn+i; j++)   {   printf(*);   }   printf(\n);   }   }   void main()   {   int n;   printf(---------开始打印符号---------\n);   printf(请输入数字:);   scanf(%d,n);   print(n);   printf(---------结束打印符号---------\n);   }   方法二:(两个for,根据条件判断实现)   #include stdio.h   //输出格式   void print(char ch) {   putchar(ch);   }   //星号   void printstar(int n)   {   int i,j; //行,列   for(i=0; i2*n-1; i++)   {   for(j=0; j2*n-1; j++)   {   if(in)   {   if(j=n-i-1jn+i)   {   print(*);   }   else   {   print( );   }   }   else   {   if(j=i-n+1j3*n-i-2)   {   print(*);   }   else   {   print( );   }   }   }   print(\n);   }   }   void main()   {   int n;   printf(---------开始打印符号---------\n);   printf(请输入数字:);   scanf(%d,n);   printstar(n);   printf(---------结束打印符号---------\n);   }   说明:(2n-1)—(n-i-1)= n+i   (2n-1)— (-(n-i-1))= 3n-i-2 以18为例 real, in each pen business lending Qian not for by pen query, led to mortgage failure of. (Vi) not in accordance with the relevant provisions of the Bank operation, failed to identify false documents, certificates, authorizations, warrants, etc. (VII) in the credit risk management system to provide false information, is not required by the guest rating credit management objective, impartial ratings of credit, resulting in credit decision-making errors. (H) the investigation report conclusions of false record, misleading statement or material omission, resulting in credit decision-making errors. (I) the orders, directives, orders, suggest that others not involved in the investigation business, issued by the investigators. (10) without the approval of authorities, after the fi

文档评论(0)

1亿VIP精品文档

相关文档