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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:08:26+00:00 2026-05-27T04:08:26+00:00

Last week i had a project from my teacher asking me to develop a

  • 0

Last week i had a project from my teacher asking me to develop a program which takes in a string (stream of integers to be precise) and calculates the sum of the numbers in the string for each number in the string ie.

if input is 31456

  • 1st loop does nothing (no number to left of 3 with result of sum as 0)
  • 2nd loop ends on 3 (with result of sum as 3)
  • 3rd loop ends on 1 (with result of 3+1 = 4)
  • 4th loop ends on 4 (with result of 3+1+4 = 8)
  • 5th loop ends on 5 (with result of 3+1+4+5 = 13)
  • 6th loop ends on 6 (with result of 3+1+4+5+6 = 19)

I did submit a working project but it is full of spaghetti code (nested loops which ends if string length is less than the number of loops) which is not a clean approach. I wondered and studied a quite a lot over this situation in vain. I have not found any way of doing this without nested for loops in C (or maybe i gave up too fast ?)

Again, i am not asking you guys for an answer to my problem but wanted to know if there is a way of doing this without the nested loops (which will have problem if length of input > number of nested loops).

  • 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. Editorial Team
    Editorial Team
    2026-05-27T04:08:27+00:00Added an answer on May 27, 2026 at 4:08 am

    Here is my advice: stop thinking in “loops” and start thinking in “steps”. If the input string has n characters, you have n+1 steps.

    Now, ponder the following three questions:

    1. Do you know the solution to the first step (no digits)?
    2. Given the solution to step k, how can you compute the solution to step k+1?
    3. How can you combine questions 1 and 2 to solve your entire problem with just a single loop?

    Since this is homework, I’ll let you take it from here.

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

Sidebar

Related Questions

I had this same problem last week, which resolved itself after I enabled impersonation.
A friend and I had an argument last week. He stated there were no
In the last week I've created two classes which my team expressed some concerns
I ran into a problem last week moving from dev-testing where one of my
I undertook an interview last week in which I learnt a few things about
Last week a released a 2.0 beta version of my Events Manager plugin, which
I had a quiz for Threads last week and I got these 2 questions
So I had this working last week. At least, I thought I did! DataGridView
I had an assignment in school last week to implement a function for calculating
Last week we released Omniture's analytics code onto a large volume of web sites

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.