Program Discussion :: Basics
311 / 279
Write a program using command line argument to input two number and Calculate the Sum of numbers.
Answer:
#include
#include
int main(int argc, char * argv[])
{
int x,y;
if (argc == 1 || argc > 3)
{
printf("Enter Two Number\r\n");
exit(0);
}
x=atoi(argv[1]);
y=atoi(argv[2]);
printf("\nSum of two number %d and %d is : %d\r\n",x,y,x+y) ;
return 0;
}
Asked In ::
Language:
Sumit
27 Oct, 2017 12:42 AM
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[])
{
int x,y;
if (argc == 1 || argc > 3)
{
printf("Enter Two Number\r\n");
exit(0);
}
x=atoi(argv[1]);
y=atoi(argv[2]);
printf("\nSum of two number %d and %d is : %d\r\n",x,y,x+y) ;
return 0;
}
Language:
Siddhartha Paul
19 Jun, 2019 2:16 PM
import java.util.*;
public class CMDLineArg
{
public static void main(String args[])
{
System.out.println("Enter 2 numbers: ");
int x=Integer.parseInt(args[0]);
int y=Integer.parseInt(args[1]);
System.out.println("Sum of the 2 numbers is: "+(x+y));
}
}