help me write this shell script

October 20, 2009 at 10:07:57
Specs: Linux
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


See More: help me write this shell script

Report •


#1
October 20, 2009 at 10:38:10
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.


Report •

#2
October 20, 2009 at 13:08:57
Homework?

Report •

#3
October 20, 2009 at 16:47:12
Wahine: Homework?
Sounds like it, but he didn't even bother to copy/paste it correctly.

Report •

Related Solutions

#4
October 22, 2009 at 07:14:00
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


Report •

#5
October 22, 2009 at 08:24:56
#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


Report •

#6
October 22, 2009 at 12:57:55
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


Report •

#7
October 25, 2009 at 18:57:55
thank you very much

Report •


Ask Question