Question

Write a script that will produce the output as the following runs: bash-3.00$ isNumPN 5 5...

Write a script that will produce the output as the following runs:

bash-3.00$ isNumPN 5
5 number is positive
bash-3.00$ isNumPN   -45
-45 number is negative
bash-3.00$ isNumPN
./isnumPN : You must give/supply one integers
bash-3.00$ isNumPN 0
0 number is negative

0 0
Add a comment Improve this question Transcribed image text
Answer #1

===========Bash Script=============

#!/bin/bash

# $# gives the number of arguments

# case when the no of arguments are not 1

if [ "$#" -ne 1 ]; then

    echo "You must give/supply one integers"

# if number is negative

elif [ $1 -lt 0 ]

then

    echo "$1 number is negative"

# if number is positive

elif [ $1 -gt 0 ]

then

    echo "$1 number is positive"

# if number is 0

else

    echo "$1 number is negative"

fi


Sample Output

0 number is negative

===============C language=====================

#include<stdio.h>

int main(int argc, char *argv[])

{

    // if no of arguments is not 1

    if( argc != 2 )

    {

        printf("You must give/supply one integers");

       

        // exit the program

        exit(0);

    }

   

    // convert string into int using atoi() function

    int n = atoi( argv[1] );

   

    // if number is negative

    if( n <= 0 )

        printf("%d is negative", n);

    // if number is positive

    else

        printf("%d is positive", n);

       

    return 0;

}


Sample Output

0 number is negative

Add a comment
Know the answer?
Add Answer to:
Write a script that will produce the output as the following runs: bash-3.00$ isNumPN 5 5...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT