C program to find the sum of N integer numbers using command line arguments
In this program, we are going to find the sum of N integer numbers and numbers will be provided through the command line, we can pass any number of integer values (in this example, we are providing 6 integer numbers) and program will find and print the sum of all input numbers.
Sample input
./main 10 20 30 40 50 60
Here, ./main is the program's executable file name, 10 20 30 40 50 and 60 are the input values.
Sample output
arg[ 1]: 10
arg[ 2]: 20
arg[ 3]: 30
arg[ 4]: 40
arg[ 5]: 50
arg[ 6]: 60
SUM of all values: 210
Program to find the sum of N integer numbers using command line arguments in C
Output
What is atoi()?
atoi() is a library function that converts string to integer, when program gets the input from command line, string values transfer in the program, we have to convert them to integers (in this program). atoi() is used to return the integer of the string arguments.
need an explanation for this answer? contact us directly to get an explanation for this answer