Computing.Net > Forums > Programming > help me write this shell script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

help me write this shell script

Reply to Message Icon

Name: leonstk
Date: October 20, 2009 at 10:07:57 Pacific
OS: Linux
Subcategory: General
Comment:

Pleaseenter a non-negative number: 3

3! = 3 X 2X 1
= 6

Pleaseenter a non-negative number: 10

10! = 10 X9 X 8 X 7 X 6 X 5 X 4 X 3 X 2 X 1
= 3628800


Pleaseenter a non-negative number: -1

Invalid input

one iswrite using for loop
and other is write using while loop
p/s:output like above



Sponsored Link
Ads by Google

Response Number 1
Name: ace_omega
Date: October 20, 2009 at 10:38:10 Pacific
Reply:

Can you post your code?

Your English is so bad that it is hard to understand what you want. It sounds like you are looking for Absolute Values. If that is the case please specify.


0

Response Number 2
Name: Wahine
Date: October 20, 2009 at 13:08:57 Pacific
Reply:

Homework?


0

Response Number 3
Name: Razor2.3
Date: October 20, 2009 at 16:47:12 Pacific
Reply:

Wahine: Homework?
Sounds like it, but he didn't even bother to copy/paste it correctly.


0

Response Number 4
Name: leonstk
Date: October 22, 2009 at 07:14:00 Pacific
Reply:

i want to know how to write those code

One is using for loop only, write a shell script to calculate
factorial like example

And other one is using while loop only, write a shell script to
calculate factorial like example


0

Response Number 5
Name: leonstk
Date: October 22, 2009 at 08:24:56 Pacific
Reply:

#include <stdio.h>
#include <stdlib.h>

int main(void){

int factorial;
printf("Please enter a nonnegative integer: ");
scanf("%d",&factorial);

int i;
int answer=1;

for(i = factorial; i > 0; i--)
{
answer *= i;


}
printf("%d! is %d\n",factorial,answer);

system("PAUSE");
return 0;

}

plz help me change to shell script code


0

Related Posts

See More



Response Number 6
Name: nails
Date: October 22, 2009 at 12:57:55 Pacific
Reply:

Since you did it in "C", I'll do it in bash shell:

#!/bin/bash

printf "Please enter a nonnegative integer: "
read factorial

i=$factorial
answer=1
while [[ $i -ne 0 ]]
do
   ((answer*=i))
   ((i -= 1))
done

printf "%d! is %d\n", $factorial $answer


1

Response Number 7
Name: leonstk
Date: October 25, 2009 at 18:57:55 Pacific
Reply:

thank you very much


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: help me write this shell script

writing a shell script menu www.computing.net/answers/programming/writing-a-shell-script-menu-/18296.html

Shell script to obtain user details www.computing.net/answers/programming/shell-script-to-obtain-user-details/18647.html

HElp me with this c++ program plez. www.computing.net/answers/programming/help-me-with-this-c-program-plez/9940.html