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
प्रश्न-20 उचित स्थान पर विराम चिह्न लगाइए
prohojiy [21]

Answer: HIND TOENGLISH TRANSALATION

Explanation:  Question-20 Put punctuation marks at the appropriate place

a) Kamal you are truly extraordinary

b) Subhash Chandra Bose said you give me blood, I will give you freedom

c) Are you Mr. Pravesh Verma

d) In every society there are all kinds of people good and bad, poor and rich, small and big.

e) Friends, now the time has come to die on the country.

3 0
3 years ago
Who is better, Tom, Ben, Hank, Angela, or Ginger
Maslowich

Answer:

Tom

Explanation:

5 0
2 years ago
Read 2 more answers
Write a static method named evenNumbers that accepts a string of text as a parameter. Assume that the text is a series of intege
Allisa [31]

Answer:

// Program is written in Java Programming Language

// Comments are used for explanatory purpose

// Import input/output and utility libraries

import java.io.*;

import java.util.*;

Declare class/

public class Numbers {

// Main method goes here

public static void main(String[] args) throws FileNotFoundException

{

// Read input from text file evenFile.txt; Assume file name is evenFile.txt

Scanner input = new Scanner(new File("evenFile.txt"));

// Call static method here

evenNumbers(input);

}

// Static method evenNumbers begins here

public static void evenNumbers(Scanner input)

{

// Declare and initialise Variables

String Nums = input.nextLine(); // Read all number in txt file

Scanner numbers = new Scanner (Nums);

int count = 0; // Number count

int evens = 0; // Even count

int sum = 0; // Summation of numbers

// Check if number is integer. If yes, continue the below operations

while (numbers.hasNextInt())

{

int num = numbers.nextInt();

count++;

sum = sum + num;

if(num % 2 == 0) // check for even

{

evens++;

}

}

System.out.println("Total numbers= " + count); // Print total number

System.out.println("Sum of numbers = " + sum); // Print summation of numbers

System.out.println("Total evens = " + evens); // Print total even

//Calculate and print percentage of even number

double percent = ((double)evens/count)*100.0);

System.out.println("Percent of even number = " +percent);

}

}

// End of program

8 0
3 years ago
Read 2 more answers
Which tool will be useful in darkening a subject’s hair color in a photograph? A.Dodge tool B.Burn tool C.Patch tool D.Blur tool
choli [55]
It's B. The burn tool darkens stuff. The dodge tool lightens stuff. hope this helps, have an amazing day :)
8 0
3 years ago
Read 2 more answers
Why should social security numbers never be given over the telephone?
nordsb [41]
Because you never know if the person over the phone is trying to scam you or not, so if you were to give them your ssn they would use your identity for stuff that they want. I hope this helps :) 
7 0
3 years ago
Other questions:
  • To retrieve an outlook express e-mail header right-click the message, and then click ____ to open a dialog box showing general i
    7·1 answer
  • 6.6 Write a function named timesTen. The function should have an integer parameter named number. When timesTen is called, it sho
    7·1 answer
  • How to format an APA paper set it up
    15·1 answer
  • Which technology has the potential to be misused to make atomic bombs? A. computer technology B. nuclear technology C. medical t
    14·1 answer
  • When you open your word-processing program, it opens in a<br> field<br> menu
    9·2 answers
  • Is a MODEM required for Internet Connectivity ?<br> Yes<br> No
    9·2 answers
  • Animations<br> Animations are !<br> Blank which can be Applied to blank in a presentation?
    7·1 answer
  • Select the correct answer.
    15·1 answer
  • Choose the statement that is true please help me fast like right now
    12·1 answer
  • Hlo Brainlians !!
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!