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]
2 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]2 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
Write a SELECT statement that returns four columns from the Invoices table, named Number, Total, Credits, and Balance: Number Co
AleksAgata [21]

Answer and Explanation:

For returning four columns from the  Invoices table, named Number, Total, Credits, and Balance the SELECt statement is as follows

Select     Invoice Number     As     Number

              Invoice Total          As      Total

Payment total + credit total  As      Credits

Invoice total

(Payment total + credit total) As     Balance

These are displayed as above

7 0
3 years ago
Given these values for the boolean variables x,y, and z:
Mumz [18]

Answer:

1. True.

2. False.

3. True.

4. True.

Explanation:

Remember OR operator (||) gives false when both of it's operands are false. AND Operator (&&) gives false when even one of it's operator is false.

In first part we have  

!(True || False) || True

=!True||True

=False||True

=True

In second part we have.

False && True && True

= False && True

=False.

In Third part

! True || (False || True)

=False || True

=True.

In fourth part

True || True && False

=True|| False

=True.

7 0
3 years ago
Why don’t we need to know and memorize the IP addresses for our favorite websites?
Solnce55 [7]

Because we have the domain name system (DNS). It registers friendly names, e.g., google.com that represent IP addresses. Your computer will consult a DNS service to query the IP address for a domain name you enter, and under-the-hood the connection is made to the IP address.

4 0
3 years ago
A college meal plan allows students to:
Licemer1 [7]
A college meal plan allows students to  PAY UPFRONT TO EAT A SPECIFIC NUMBER OF MEALS IN THE COLLEGE CAFETERIAS. Many colleges give students some degree of freedom when it comes to the choice of meal plans to sign up for. Students have to pay in advance for any meal they decide for. 
8 0
2 years ago
Read 2 more answers
In a system with non-preemptive scheduling, the CPU scheduler is invoked when: (a) a process switches from the running state to
VARVARA [1.3K]
Ghdhdhhdhdhdhdhdhdhdhdhhdhdhd
7 0
3 years ago
Other questions:
  • I need someone whos really good with computers to help me with some things
    12·1 answer
  • Why is continual user involvement a useful way to discover system requirements? Under what conditions might it be used? Under wh
    5·1 answer
  • Jeremy Aronoff has purchased a new laptop. He wants to customize the operating system to meet his
    7·1 answer
  • According to the "multiple-selves" theory, of an online DVD rental service could offer same-day deliveries, so that people who o
    9·1 answer
  • You have just purchased a motherboard that has an LGA 1156 socket for an Intel Pentium processor. What type of memory modules wi
    14·1 answer
  • define a function named quarter_num that has one parameter number and return quarter of the number. For example: if we called th
    7·1 answer
  • The radix sort
    7·1 answer
  • What is adobe photoshop?
    10·2 answers
  • Hvhblfffffffff<br> eafafaefafsa
    9·2 answers
  • What<br>are<br>the features of secondary storage media​
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!