Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 159053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:47:26+00:00 2026-05-11T10:47:26+00:00

The program is supposed to calculate the number of arguments, iterate over the list

  • 0

The program is supposed to calculate the number of arguments, iterate over the list of arguments, for each argument convert the argument to an integer and copy it to an array, iterate over the elements of the array, adding the value of each one to a variable (this computes the sum of elements), and print the sum. There will not be more than 15 arguments. So far I have:

int sumofA (int sizeofA, int x, int y){     int i = sizeofA;      if (i <= 15){         int z = x + y;         return z;      }   }    int main (int argc, char*argv[]){        int sizeofA = argc - 1;      int i = 1;      while (i <= sizeofA){         int x = GetInt (argc, argv, i);         i = i + 1;         int y = GetInt (argc, argv, i);            printf ('%d\n', sumofA (sizeofA, x, y));    }      return 0;   }   

Ok, now (when given three arguments other than ./a) it prints the sum of the first argument and the second argument…then the second and the third…and then the value of the third argument. Why?

Here’s the code for GetInt (I have to use this):

int GetInt (int argc, char * argv[], int i) {      if (i < 0 || i >= argc) return 0;      return atoi(argv[i]);   }   

Do I need to go through and assign each argument to an integer (ex. int z = GetInt (argc, argv, i + 2) )?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:47:27+00:00Added an answer on May 11, 2026 at 10:47 am

    There are a couple of this going wrong here:

    • i is not defined in sumofA, so comparing with it yield undefined behavior.
    • If i >= 15, then it’s unclear what sumofA will return.
    • You return inside the loop; surely that’s not what you want.
    • Your code is not actually storing anything in the array A.

    Please compile your code with all warning-flags on (gcc: -Wall -Werror -pedantic), and make sure there are no warnings when your code compiles.

    Note that the variable size is unneeded: use while (i < argc).

    Edit: Now that you added the code of GetInt, replace

    GetInt (argc, argv, i); 

    with

    atoi(argv[i]); 

    There is no use for GetInt, so you can remove it completely.

    Lastly: in your question you mention storing the numbers in an array and then summing them. Do you want to do that, or need to do that (due to some assignment?) Because it’s not necessary: simply add the result of all calls to atoi. The array A is then superfluous.

    Edit 2: I see you fixed the code in some places. Your code currently (23:31 CEST) adds the first argument to each of the arguments separately and prints them. You’re not quite there yet. Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 68k
  • Answers 68k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You can do that using reflection. PropertyInfo prop = typeof(Customer).GetProperty… May 11, 2026 at 12:06 pm
  • added an answer To make LIKE Statements, you can use the Contains method:… May 11, 2026 at 12:06 pm
  • added an answer There are attributes in VB.NET too: https://msdn.microsoft.com/en-us/library/system.obsoleteattribute(v=vs.110).aspx http://www.vb-helper.com/howto_net_obsolete_attribute.html Looks like… May 11, 2026 at 12:06 pm

Related Questions

The program is supposed to accept telnet connections on port 8888 and then send
Here is the story. I was doing a program, every time the program is
The following program is very simple: it outputs a single dot each half a
Is there a way to find the name of the program that is running
The target language is C/C++ and the program has only to work on Linux,
Okay here's the program I have typed up(stdio.h is included also): /* function main
This snippet of Perl code in my program is giving the wrong result. $condition
My app is installed via NSIS. I want the installer to install the program
One of the feature requests I've got for the program I'm working on is
I need a way to determine whether the computer running my program is joined

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.