Total Pageviews

Tuesday, January 24, 2023

Unix Shell Programming Example for B.Sc, B.Tech, BCA, MCA

 1. Use of while loop.

PROGRAM:

echo "enter no. of elements:"
read n
a=0
while [ $a -ne $n ]
do
    echo $a
    ((a++))
done

OUTPUT:

[bgc@localhost ~]$ sh pc1.sh
enter no. of elements:
3
0
1
2
[bgc@localhost ~]$

1 comment:

  1. PROGRAM:

    echo "While Loop Example";

    echo "form method='post'
    Enter a number:
    input type='number' name='number' required
    input type='submit' value='Submit'
    /form";

    if(isset($_POST['number'])) {
    $n = $_POST['number'];
    $i = 1;

    echo "Output:";

    while($i <= $n) {
    echo $i .
    $i++;
    }
    }

    ?


    OUTPUT:
    [http://localhost/While.php]
    Enter a number:
    Output:
    1
    2
    3
    4
    5
    6
    7
    8
    9

    ReplyDelete