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 127857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:32:35+00:00 2026-05-11T05:32:35+00:00

Write a program that sums the sequence of integers as well as the smallest

  • 0

Write a program that sums the sequence of integers as well as the smallest in the sequence. Assume that the first integer read with scanf specifies the number of values remaining to be entered. For example the sequence entered:

Input: 5 100 350 400 550 678

Output: The sum of the sequence of integers is: 2078

Input: 5 40 67 9 13 98

Output: The smallest of the integers entered is: 9

This is a daily problem I am working on but by looking at this, Isnt 5 the smallest integer? I have no idea how to write this program. Appreciate any help

  • 1 1 Answer
  • 0 Views
  • 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-11T05:32:36+00:00Added an answer on May 11, 2026 at 5:32 am

    First thing, the 5 is not considered part of the list, it’s the count for the list. Hence it shouldn’t be included in the calculations.

    Since this is homework, here’s the pseudo-code. Your job is to understand the pseudo-code first (run it through your head with sample inputs) then turn this into C code and try to get it compiling and running successfully (with those same sample inputs).

    I would suggest the sample input of ‘2 7 3’ (two items, those being 7 and 3) as a good start point since it’s small and the sum will be 10, smallest 3.

    If you’ve tried to do that for more than a day, then post your code into this question as an edit and we’ll see what we can do to help you out.

    get a number into quantity set sum to zero loop varying index from 1 to quantity     get a number into value     add value to sum     if index is 1         set smallest to value     else         if value is less than smallest             set smallest to value         endif     endif endloop output 'The sum of the sequence of integers is: ', sum output 'The smallest of the integers entered is: ', smallest 

    Stack Overflow seems to be divided into three camps, those that will just give you the code, those that will tell you to push off and do your own homework and those, like me, who would rather see you educated – by the time you hit the workforce, I hope to be retired so you won’t be competing with me :-).

    And before anyone picks holes in my algorithm, this is for education. I’ve left at least one gotcha in it to help train the guy – there may be others and I will claim I put them there intentionally to test him :-).


    Update:

    Robert, after your (very good) attempt which I’ve already commented on, this is how I’d modify your code to do the task (hand yours in of course, not mine). You can hopefully see how my comments modify the code to reach this solution:

    #include <stdio.h> int main (int argCount, char *argVal[]) {     int i;              // General purpose counter.     int smallNum;       // Holds the smallest number.     int numSum;         // Holds the sum of all numbers.     int currentNum;     // Holds the current number.     int numCount;       // Holds the count of numbers.      // Get count of numbers and make sure it's in range 1 through 50.      printf ('How many numbers will be entered (max 50)? ');     scanf ('%d', &numCount);     if ((numCount < 1) || (numCount > 50)) {         printf ('Invalid count of %d.\n', numCount);         return 1;     }     printf('\nEnter %d numbers then press enter after each entry:\n',         numCount);      // Set initial sum to zero, numbers will be added to this.      numSum = 0;      // Loop, getting and processing all numbers.      for (i = 0; i < numCount; i++) {          // Get the number.          printf('%2d> ', i+1);         scanf('%d', &currentNum);          // Add the number to sum.          numSum += currentNum;          // First number entered is always lowest.          if (i == 0) {             smallNum = currentNum;         } else {             // Replace if current is smaller.              if (currentNum < smallNum) {                 smallNum = currentNum;             }         }     }      // Output results.      printf ('The sum of the numbers is: %d\n', numSum);     printf ('The smallest number is:    %d\n', smallNum);      return 0; } 

    And here is the output from your sample data:

    pax> ./qq How many numbers will be entered (max 50)? 5  Enter 5 numbers then press enter after each entry:  1> 100  2> 350  3> 400  4> 550  5> 678 The sum of the numbers is: 2078 The smallest number is:    100  pax> ./qq How many numbers will be entered (max 50)? 5  Enter 5 numbers then press enter after each entry:  1> 40  2> 67  3> 9  4> 13  5> 98 The sum of the numbers is: 227 The smallest number is:    9  pax> ./qq How many numbers will be entered (max 50)? 0 Invalid count of 0.  [fury]$ ./qq How many numbers will be entered (max 50)? 51 Invalid count of 51. 

    By the way, make sure you always add comments to your code. Educators love that sort of stuff. So do developers that have to try to understand your code 10 years into the future.

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

Sidebar

Related Questions

I have to write a program that read from a file that contains the
Write a program that takes 3 integers separated by spaces and perform every single
I want to write a program that would print every combination of a set
I would like to write a program that will identify a machine( for licensing
I'm trying to write a program that uses sockets to connect with other instances
I want to write a small program that should print something like testing CPU...
I am trying to write a C++ program that takes the following inputs from
I am trying to write a fragment program that will take a texture and
I need to write a small program that can detect that it has been
I'd like to be able to write a ruby program that can restart without

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.