# Command Line Arguments Programming Questions with their Solutions

In 4th section of TCS Online Round for campus recruitment you have to solve a programming question. To solve this 4th section question you can’t use keywords like **“scanf, getc, getch, getchar”**so to solve this type of coding problem. You have to use input from **command line****. **Below are some programs of same type which will explain how to take input from** command line.**

**1.Factorial**

Write a C program to calculate the factorial of a non negative integer N. The factorial of a number N is defined as the product of all integers from 1 up to N. Factorial of 0 is defined to be 1.Write the output to stdout formatted as an integer WITHOUT any other additional text. You may assume that the input integer will be such that the output will not exceed the largest possible integer that can be stored in an int type variable.The number N is a non negative integer that will be passed to the program as the first command line parameter.

**2. Area of Triangle**

Write a C program to find the area of a triangle given the base and the corresponding height.Write the output to stdout formatted as a floating point number rounded to EXACTLY 2 decimal precision WITHOUT any other additional text.The values base and height are both positive integers passed to the program as the first and second command line parameters respectively.

Scientific format(such as 1.00E+5) should NOT be used while printing the output.

You may assume that the inputs will be such that the output will not exceed the largest possible real number that can be stored in a float type variable.

3. **Square Root of Prime Number**

Write a C program which will check whether a given number N is a Prime or Not. If the Number N is a Prime, then find it’s square root and print that value

to the STDOUT as floating point number with exactly 2 decimal precision.

If the number is not Prime, then print the value 0.00 to STDOUT.

The given number will be positive non zero integer and it will be passed to the program as first command line argument.

Other that floating point No other information should be printed to STDOUT.

4. **Nth Fibonacci Number**

The given number will be positive non zero integer and it will be passed to the program as first command line argument.

5. **Armstrong Number**

Write a C program which will check whether a given number N is a Armstrong or Not.

The given number will be positive non zero integer and it will be passed to the program as first command line argument.

**6. Palindrome Number**

Write a C program which will check whether a given number N is a Armstrong or Not.

**7. Decimal to Binary**

Write a C program which will convert Decimal number to its Binary equivalent.

**8. Binary to Decimal**

Write a C program which will convert Binary number to its Decimal equivalent.

The given number will be containing only 0 and 1, and it will be passed to the program as first command line argument.

**9. Calculating sqrt without using sqrt() function**

Write a C program which will calculate the square root of a number without using math.h’s sqrt() function and print that sqrt to the STDOUT as floating point number with exactly 2 decimal precision.

**10. Area Of Circle**

Write a C program to find the area of a circle with radius provided.Write the output to stdout formatted as a floating point number rounded to EXACTLY 2 decimal precision WITHOUT any other additional text.The value of radius positive integer passed to the program as the first command line parameter.

Scientific format(such as 1.00E+5) should NOT be used while printing the output.

You may assume that the inputs will be such that the output will not exceed the largest possible real number that can be stored in a float type variable.

**11. Sum Of Digits Of a Number**

Write a C program which will calculate the sum of all the digits of a Number.

**12. Reverse a Number**

Write a C program which will reverse all the digits of a Number.

To run these programs on your windows machine you have to copy and paste code in code blocks. Then build program →go to the folder where programs are saved or where programFile.exe exist and run cmd there → type command programFile.exe argument.

As shown below.

Thanks for reading.

Author: Alok Shakya