Program Discussion :: Basics
316 / 279
Write a program using command line argument to input one number and print the Factorial of the number.
Answer:
#include
#include
int main(int argc, char * argv[])
{
int fact = 1,c = 0, num = 0;
if(argc == 1 || argc > 2)
{
printf("Enter the number \n");
exit(1);
}
num = atoi(argv[1]);
for (c = 1; c
Asked In ::
Language:
Om Prakesh
28 Oct, 2017 4:48 PM
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[])
{
int fact = 1,c = 0, num = 0;
if(argc == 1 || argc > 2)
{
printf("Enter the number \n");
exit(1);
}
num = atoi(argv[1]);
for (c = 1; c <= num ; c++)
fact *= c;
printf("Factorial of %d = %d\n", num, fact);
return 0;
}
Language:
Siddhartha Paul
19 Jun, 2019 2:16 PM
import java.util.*;
public class Factorial
{
public static void main(String []args)
{
int fact=1;
System.out.println("Enter a numbers: ");
int a=Integer.parseInt(args[0]);
for(int i=1;i<=a;i++)
{
fact=fact*i;
}
System.out.println("Factorial of the given number is: "+fact);
}
}