plz tell me how to print * triangle
like this
*
**
***
****
*****
plz tell me how to print * triangle
like this
*
**
***
****
*****
Can you dictate coding you have done on it. so that I can better help you out?
Regards,
Raj Kumar Arora
for i in 1 2 3 4 5
do
j=0;
while [ $j -lt i ]
do
echo "* \c"
j=$(( j + 1 ))
done
echo ""
done
#!/bin/ksh
str="*"
for i in 1 2 3 4 5
do
echo "$str"
str="$str *"
done
thanks fpmurphy its working buddy:b:
A curious way:
>awk 'BEGIN{ while ( i < 5 )
{
i++
$i=OFS="*"
print
$i=""
}
}'
*
**
***
****
*****
Hi Klashxx,
What OFS in Print statement does?
I am new to AWK so i didnt have no idea what OFS means?
Thanks,
Raamc
# awk 'NR<6{a=sprintf("%0"NR"s","*");gsub("0","*",a); print a}' /etc/services
*
**
***
****
*****
>awk 'BEGIN{
while ( i < 5 )
{
i++
$i=OFS="*"
print
$i=""
}
}'
Hi , you don�t need a input file , this awk has only a begin part (execuded once before any input is read).
Then we can change dinamically the number of fields ($i), and assign value to it.
Ex:
> awk 'BEGIN{$5="x";print}'
x
As you see , with this litle trick we order awk to print the 5th field with value "x".
OFS is the Output Field Splitting ,by default its value is a blank space, we didn't change it so the output of the previous statement is four blanks (because in five fields we have 4 field separators).
Next step:
> awk 'BEGIN{$5=OFS="x";print}'
xxxxx
Here we changed the OFS to "x" so the awk prints four OFS "xxxx" and the 5th field "x".
Finally we have to set the $i variable to null cause ,if we don't do that , the variable $i will have value "*" at i postion , like in this example:
> awk 'BEGIN{ while ( i < 5 )
{
i++
OFS="*"
$i="o"
print
}
}'
o
o*o
o*o*o
o*o*o*o
o*o*o*o*o
Regards
$ echo "*
> **
> ***
> ****
> *****"
*
**
***
****
*****
$
sometimes is funny how we make things complicated
what if number of * doesn't stop at 5?
But, it does. I counted. What if we were supposed to display pentagon?