
Patrick B. answered 02/13/21
Math and computer tutor/teacher
#include <stdio.h>
int main()
{
int n;
int i,x,y;
printf(" Enter the height of the pattern (must be greater than zero): ");
scanf("%d",&n);
if (n>0)
{
for (i=1; i<=n; i++)
{
for (x=0; x<i-1; x++)
{
printf("* ");
}
printf(" %d ",i);
for (y=0; y<i-1; y++)
{
printf(" *");
}
printf("\n");
}
}
else
{
printf("Invalid Entry! \n");
}
}
-----------------------------------------------------
.LC0:
.string " Enter the height of the pattern (must be greater than zero): "
.LC1:
.string "%d"
.LC2:
.string "* "
.LC3:
.string " %d "
.LC4:
.string " *"
.LC5:
.string "Invalid Entry! "
main:
push rbp
mov rbp, rsp
sub rsp, 16
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call printf
lea rax, [rbp-16]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call __isoc99_scanf
mov eax, DWORD PTR [rbp-16]
test eax, eax
jle .L2
mov DWORD PTR [rbp-4], 1
.L8:
mov eax, DWORD PTR [rbp-16]
cmp DWORD PTR [rbp-4], eax
jg .L3
mov DWORD PTR [rbp-8], 0
.L5:
mov eax, DWORD PTR [rbp-4]
sub eax, 1
cmp DWORD PTR [rbp-8], eax
jge .L4
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
add DWORD PTR [rbp-8], 1
jmp .L5
.L4:
mov eax, DWORD PTR [rbp-4]
mov esi, eax
mov edi, OFFSET FLAT:.LC3
mov eax, 0
call printf
mov DWORD PTR [rbp-12], 0
.L7:
mov eax, DWORD PTR [rbp-4]
sub eax, 1
cmp DWORD PTR [rbp-12], eax
jge .L6
mov edi, OFFSET FLAT:.LC4
mov eax, 0
call printf
add DWORD PTR [rbp-12], 1
jmp .L7
.L6:
mov edi, 10
call putchar
add DWORD PTR [rbp-4], 1
jmp .L8
.L2:
mov edi, OFFSET FLAT:.LC5
call puts
.L3:
mov eax, 0
leave
ret