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
yaroslaw [1]
3 years ago
11

Write code for a function that uses a loop to compute the sum of all integers from 1 to n. Do a time analysis, counting each bas

ic operation (such as assignment and ++) as one operation.
Computers and Technology
1 answer:
tekilochka [14]3 years ago
8 0

Answer:

#include<bits/stdc++.h>  

using namespace std;  

int sumOfinteger(int );  

  // Returns sum of all digits in numbers from 1 to n  

int sumOfintegersFrom1ToN(int n)  {  

   int result = 0; // initialize result  

    // One by one compute sum of digits in every number from  

   // 1 to n  

   for (int x = 1; x <= n; x++)  

       result += sumOfinteger(x);  

   return result;  

}  

  // A utility function to compute sum of digits in a  

// given number x  

int sumOfinteger(int x)  {  

   int sum = 0;  

   while (x != 0)  {  

      sum += x %10;  

       x   = x /10;  }  

   return sum;  }  

  // Driver Program  

int main()  {  

   int n ;  

   cout<<"enter a number between 1 and n : ";

   cin>>n;

   cout << "Sum of digits in numbers from 1 to " << n << " is " << sumOfDigitsFrom1ToN(n);  

   return 0;  }

You might be interested in
Main function of Ubuntu
Lynna [10]

Answer:

Ubuntu includes thousands of pieces of software, starting with the Linux kernel version 5.4 and GNOME 3.28, and covering every standard desktop application from word processing and spreadsheet applications to internet access applications, web server software, email software, programming languages and tools

Explanation:

5 0
3 years ago
Read 2 more answers
A _______ is used to present data in a simplified, graphical format that allows your audience to read less text while still bein
steposvetlana [31]
Your correct answer would be Legend.


answer choice is B.
3 0
4 years ago
Read 2 more answers
A household consists of a married couple and their twin five-year old daughters. The couples children had no income and lived wi
Colt1911 [192]

Answer:

APEX- 4.

Explanation:

4 0
3 years ago
Read 2 more answers
________ is a condition in which information inflow exceeds an individual's processing capacity. Select one: a. Information over
In-s [12.5K]

Answer:

Option a is the correct answer.

Explanation:

  • The information overflow is a state where the coming information will be more in comparison with processing information.
  • For example, if there is limited space and any user has more luggage to keep on that space, then we can say that the luggage is overflow.
  • So when the information is more and the processing capacity is less then we can say it information overflow condition and it is also asked by the above question. Hence option a is the correct answer.
  • While the other is not because:- option b, c and d states some information statements which do not come in any information condition.
6 0
3 years ago
A document called a system requirements report describes the objectives for the information system.
kkurt [141]
A, true. Requirements describe the objectives of any assignment.
6 0
3 years ago
Other questions:
  • If you are trying move a hard drive from a non-working computer to a working computer for the purposes of accessing the data on
    5·1 answer
  • Most sim cards allow ___________ access attempts before locking you out.
    10·1 answer
  • Why do you need to back up important data?
    5·2 answers
  • Using data from the BITS database, define a view named TopLevelClient. It consists of the number, name, address, balance, and cr
    9·1 answer
  • What is ambient sound, and what is its purpose in film? When can it be a drawback ?
    7·1 answer
  • While typing out his assignment henry makes use of leading. What could be the probable reason for him to do so.
    9·2 answers
  • An organization has hired a new remote workforce. Many new employees are reporting that they are unable to access the shared net
    11·1 answer
  • You have a spreadsheet of x values that need to
    15·2 answers
  • Computer that process digital as well as analogue signals​
    11·1 answer
  • Create a simple program of your own using a Loop that counts and displays numbers 1-10.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!