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
Which amendment discussed in the unit do you think has the greatest effect on your life? Why?
lora16 [44]
The 13th amendment (freed the slaves) for me because I am black
6 0
3 years ago
Southern States<br> Wanted...<br> But...<br> So...
Dvinal [7]
The southern states wanted slavery, but the northern did not, so they had a civil war. :P
8 0
3 years ago
Which of the following are the functions of an os?
cricket20 [7]
Manage the computer's resources, such as the central processing unit, memory, disk drives, and printers, (2) establish a user interface, and (3) execute and provide services for applications software.
6 0
3 years ago
I need help with this work
lisabon 2012 [21]

Answer:

B. Balanced depending and the type of questions

5 0
3 years ago
A common preprocessing step in many natural language processing tasks is text normalization, wherein words are converted to lowe
Arturiano [62]

Answer:

def normalize(text):

   text = text.lower()

   text = text.split()

   return text

Explanation:

The functiinfunction is provided with an input text when called upon, then it changes every character in the text into lower case and split each word with a space.

4 0
3 years ago
Other questions:
  • An important advantage of using GUI data-entry objects is that you often can control what users enter by limiting their options?
    6·1 answer
  • How is the Task Manager helpful in displaying which resources your computer is using and how fast?
    5·2 answers
  • What is TRUE about the following array?
    15·1 answer
  • Given two Generic variables, A with value "123" and B with value 456, what would the Write Line output of A + B be? 123456 579 A
    5·1 answer
  • "Because Standard Error and Standard Ouput represent the results of a command and Standard Input represents the input required f
    6·1 answer
  • In a study on software license infringement, those from United States were significantly more permissive than those from the Net
    15·1 answer
  • 3. When you right-click a linked spreadsheet object, what commands do you choose to activate the Excel features?
    7·2 answers
  • I need help with writing the code in Python that draws an arrow pointing to the right.
    15·1 answer
  • Hurry im TIMED
    8·1 answer
  • Unconformities develop when new sedimentary layers accumulate atop old, eroded layers, resulting in a geologic hiatus. Which of
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!