Showing posts with label Shell Scripting. Show all posts
Showing posts with label Shell Scripting. Show all posts

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";
    }

 

 


Saturday, May 30, 2020

If statement compound condition matching

#!/bin/ksh
#prompt the user to enter a number
print -n "Enter your age: "
read age
print
print -n "enter the number of children you have :"
read numberofchildren
if ( (( age < 30 )) && (( numberofchildren==0 )) ); then #the space after the ( and before the ) is important

print "Single and loving it"
fi
if (  ((age > 30)) || ((numberofchildren!=0)) ); then
print "things could be worse"
fi
#operators are &&,||