Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Pleaseenter a non-negative number: 3
3! = 3 X 2X 1
= 6Pleaseenter 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: -1Invalid input
one iswrite using for loop
and other is write using while loop
p/s:output like above

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.

i want to know how to write those code
One is using for loop only, write a shell script to calculate
factorial like exampleAnd other one is using while loop only, write a shell script to
calculate factorial like example

#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

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

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |