-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmdprgexample.cpp
More file actions
54 lines (46 loc) · 1.16 KB
/
cmdprgexample.cpp
File metadata and controls
54 lines (46 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// C program for finding the largest integer
// among three numbers using command line arguments
#include <stdio.h>
#include <stdlib.h>
// Taking argument as command line
int main(int argc, char *argv[])
{
int a, b, c;
// Checking if number of argument is
// equal to 4 or not.
if (argc < 4 || argc > 5)
{
printf("enter 4 arguments only eg.\"filename arg1 arg2 arg3!!\"");
return 0;
}
// Converting string type to integer type
// using function "atoi( argument)"
a = atoi(argv[1]);
b = atoi(argv[2]);
c = atoi(argv[3]);
// Checking if all the numbers are positive of not
if (a < 0 || b < 0 || c < 0)
{
printf("enter only positive values in arguments !!");
return 1;
}
// Checking if all the numbers are different or not
if (!(a != b && b != c && a != c))
{
printf("please enter three different value ");
return 1;
}
else
{
// Checking condition for "a" to be largest
if (a > b && a > c)
printf("%d is largest", a);
// Checking condition for "b" to be largest
else if (b > c && b > a)
printf ("%d is largest", b);
// Checking condition for "c" to be largest..
else if (c > a && c > b)
printf("%d is largest ",c);
}
return 0;
}