C Program to Add Two Integers using command line arguments

  • Tech Area
  • April 25, 2024



In this tutorial, We will add two integers using command line arguments in C programming language.

Program to Add Two Integers

#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c;
clrscr();
printf("Enter the value of a = ");
scanf("%d", &a);
printf("Enter the value of b = ");
scanf("%d", &b);
c = a + b;
printf("The sum of a and b is = %d", c);
getch();
}

Output

Enter the value of a = 10
Enter the value of b = 20
The sum of a and b is = 30

In this program, the user is asked to enter two integers. These two integers are stored in variables a and b respectively.

printf("Enter the value of a = ");
scanf("%d", &a);
printf("Enter the value of b = ");
scanf("%d", &b);

Then, these two numbers are added using the + operator, and the result is stored in the c variable.

c = a + b;

The printf() function is used to display the sum of numbers.

printf("The sum of a and b is = %d", c);


Subscribe us via Email

Join 10,000+ subscriber

Subscribe on YouTube