Command line arguments example in C
The problem is to find the largest integers among three using command line argument.
Notes:
int main(int argc, char *argv[]) { /* ... */ }
Examples:
Input : filename 8 9 45 Output : 45 is largest Input : filename 8 9 9 Output : Two equal number entered Input : filename 8 -9 9 Output : negative number entered
During execution of program, we pass three integers along with filename of the program and then we will find the largest numbers among three.
Approach :
- The program “return 1” if any of the two conditions satisfy:
- If any two numbers are same, print the statement “two equal numbers entered”.
- If any number is negative, print “negative number entered”.
- Else “return 0” if three different integers are entered.
For better understanding run this code on your
Output :
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.
No comments: