[Loops]D. Liang 4.19 Printing numbers in a pyramid pattern

Description
Write a program that reads an interger n, then display the n levels pyramid pattern. For example, if n=4, the pattern is as follow:

				   1
              1    2    1
         1    2    4    2    1
    1    2    4    8    4    2    1

Input
An integer n (1<=n<=8).

Output
The n levels Pattern.
You should specify the width of each number’s print field to 5, justify the output to right.

NOTE:

There is NO SPACE at the end of each line.
There is A NEWLINE (\n) at the end of last line.
That is (. indicates and ¬ indicates <newline>)

..........1¬
.....1....2....1¬

Sample Input
4
Sample Output

  				   1
              1    2    1
         1    2    4    2    1
    1    2    4    8    4    2    1

作业记录。

#include<stdio.h>
int main(){
  int n,t=1,b=1;
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
      double a=1;
      printf("%*c",5*(n-i+1)-1,32);
      printf("%d",1);
      for(t=2;i>1&&t<2*i;t++){
          for(;t<=i;t++){
              b=b*2;
              printf("%5d",b);}
          for(;t>i&&t<2*i;t++){
              b/=2;
              printf("%5d",b);
          }
      }
      printf("\n");
  }  
  return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值