1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nadusha1986 [10]
3 years ago
11

Write a program "addnumbers.c" where it takes as many arguments as the user includes as command line arguments and calculates th

e sum of all numbers entered, and prints it. You will find using function atoi() from stdlib.h library helpful, where it converts the string representation of an integral number to an int value. Compile it on a lab machine and run it using command line.

Computers and Technology
1 answer:
gogolik [260]3 years ago
8 0

Answer:

#include <stdio.h>

#include <stdlib.h>

int main(int argc, char* argv[])

{

int first, second, total;

if (argc < 2)//checking if there are enough arguments

{

 printf("not enough values\n");

 return -1;//terminate program

}

total = 0;

for (int i = 1; i < argc; i++)

{

 //atoi convert a string into int. doing this to use operator

 total = total + atoi(argv[i]);//add current total to next argumment

}

printf("final total sum: %d\n", total);//printing final total

return 0;

}

Explanation:

For command line arguments you have to use command prompt. It varies depending on you machine and where you code is placed.

So, go to command line, called "command prompt" on Windows. This should open the black screen, also called the Terminal. A picture is attached in the answer. Then you have to NAVIGATE to the directory of your program. So, let's say your code is on your desktop. You will have to navigate to your desktop. To do this, type:

"cd Desktop", and press enter.

The picture of my process is attached below too.

Then, the program we have made is called addnumbers. we will type,

"addnumbers 10 20 30 40 50"

add numbers is the name of the program followed by arguments, separated with spaces.

You might be interested in
What is one purpose of an algorithm
adelina 88 [10]

Answer:

Algorithms is formula for solving a problem. It is helpful because it specifically give instructions detail to computer to what a computer should perform a specific task.

For e.g. calculating report cards.

4 0
3 years ago
let's imagine you're searching for hotels in searching chicago, what should you search for in order to get the most relevant res
n200080 [17]

Trivago, Trip advisor,

3 0
3 years ago
The parts of a memo are _____.
Alex
The correct answer would be D
4 0
3 years ago
Read 2 more answers
It is ok to sell services on Xbox in exchange for real-world money
Sati [7]
Is this a true or false question? If it is let me know and I can help! (:
6 0
3 years ago
Read 2 more answers
___refers to self-acting or self-operating.
lisabon 2012 [21]

Answer:

do it to me watch this

Explanation:

trailing zeros in a whole number with no decimal shown are NOT significan

6 0
3 years ago
Other questions:
  • Despite its vivid design, the website for Lolly's Bookstore did not seem to attract customers who lingered. In fact, most websit
    13·1 answer
  • Kai is a software engineer who started his own IT consulting firm. His friend, Catalina, is the owner of a store that sells offi
    13·2 answers
  • You've applied a filter. What's the best way to see the original data?
    11·2 answers
  • You are given a class named Clock that has one int instance variable called hours.
    14·1 answer
  • Write a program in which given an integer num, return the sum of the multiples of num between 1 and 100. For example, if num is
    7·1 answer
  • "What technology will examine the current state of a network device before allowing it can to connect to the network and force a
    13·1 answer
  • Cash cows are always in
    7·1 answer
  • Define a lambda function that accepts one argument (a list of strings) and returns a list of only the words that start with an '
    9·1 answer
  • Zachary drinks 2 cups of milk per day. He buys 6 quarts of milk. How many days will his 6 quarts of milk last?
    12·1 answer
  • What form of contacts can be shared in Outlook 2016?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!