Please solve the C algorithm problem~~

Asked 2 years ago, Updated 2 years ago, 28 views

c

2022-09-22 15:16

1 Answers

n=int(input())
line=int(input())

for i in range(line):
    print(' '*(line-1),end='')
    #When decreasing odd numbers, it is printed in order
    if i%2==1:
        for j in range(2*i+1):
            print(n,end='')
            n=(1 if n==9 else n+1)
    #On the even-numbered reduction, it is printed in reverse order
    else:
        #n=n+2*i
        for k in range (2*i):
            n=(1 if n==9 else n+1)
        t=n
        for j in range(2*i+1):
            print(n,end='')
            if j!=2*i:
                n=(9 if n==1 else n-1)
        n=t
        n=(1 if n==9 else n+1)
    print('')
    line=line-1

It's made of Python, but it's not much different from C, so you can move it right away

Aif testelse B is the same as the triad operator test? A:B


2022-09-22 15:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.