基础编程题目求解

来源:百度知道 编辑:UC知道 时间:2024/05/21 18:49:50
Write a program that accepts a number and produces a pattern
as shown in the following sample outputs.

Line = 5
*
**
***
****
*****
____________________________________________

Line = 6
*
**
***
****
*****
******
还有一个类似的
Write a program that accepts a number and produces a pattern as
shown in the following sample outputs.
比如:
Line = 3
*.*
.*
*

Line = 8
.*.*.*.*
*.*.*.*
.*.*.*
*.*.*
.*.*
*.*
.*

是类似的,图案就是 . 和 * 的交替那种,也请帮忙解答下,谢谢

根据你的要求,我把第二个问题的答案 也给你写好了,你看下吧,记得加分哦

你的第一个问题我帮你解决了,但是你的第二个补充问题好象给的 有点问题,图案不太看的清,麻烦你补充下第二个问题,第一个问题的源代码和运行截图在下面:(但愿你能满意我的这个回答)

#include <stdio.h>

void print_star(int n)

{

 int i,j;

 for(i=1;i<=n;i++)

 {

  for(j=1;j<=i;j++)

   printf("*");

  printf("\n");

 }

}

void main()

{

 int a;

 printf("请输入一个值,line=");

 scanf("%d",&a);

 print_star(a);

 printf("\n");

}

第二个问题的答案:

#include <stdio.h>

void print_star(int n)

{

 int i,j;

 for(i=1;i<=n;i++)

 {

  for(j=n;j>=i;j--)

  {

   printf("*");

   printf(".");

&nb