Wednesday, November 16, 2022

Digonal number pattern in bash solved

  printf "Enter row number";
    read n;
    c=1
    for((i=1;i<=(n-1);i++))
    {
   
        for((j=1;j<=(n-1);j++))
        {
            if(((i==j)||(j==(n-i))))
            then
            printf $c ;
            else
            printf " ";
            fi
        }
        if ((c>=4))
        then
        ((c=c-1));
        else
        ((c=c+1));
        fi
        printf "\n";
    }

 

 


No comments:

Post a Comment