TCS Coding Practice Question | Factorial of a Number
Given a number, the task is to find the Factorial of this number using Command Line Arguments. Factorial of a non-negative integer is the multiplication of all integers smaller than or equal to n.
1 * 2 * 3 = 6
1 * 2 * 3 * 4 * 5 * 6 = 720
- Since the number is entered as Command line Argument, there is no need for a dedicated input line
- Extract the input number from the command line argument
- This extracted number will be in String type.
- Convert this number into integer type and store it in a variable, say num
- Find the reverse of this number and store in a variable, say rev_num
- Check if this rev_num and num are same or not.
- If they are not same, the number is not Palindrome
- If they are same, the number is a Palindrome
#include <stdlib.h> /* atoi */
res = 1, i;
(i = 2; i <= n; i++)
res *= i;
num, res = 0;
(argc == 1)
"No command line arguments found.\n"
; i <= n; i++)
res *= i;
num = Integer.parseInt(args[
"No command line "
- In C:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.