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
Which option describes the purpose of configuring native supplicant profile on the cisco ise?
Ulleksa [173]

The best option describes the purpose of configuring Native Supplicant Profile on the Cisco ISE is it enforces the use of MSCHAPv2 or EAP-TLS for 802.1X authentication.

8 0
3 years ago
A soft news story and a feature story are the same thing.<br> O True<br> O False<br> HELLPP ASSAAAP
bogdanovich [222]
The answer would be False!
5 0
3 years ago
Read 2 more answers
What is a type of machine-to-human communication?
suter [353]
I don’t know what it’s called but it’s where they can speak by moving there eyes
3 0
3 years ago
Describing light years
kogti [31]

Answer:

For most space objects, we use light-years to describe their distance. A light-year is the distance light travels in one Earth year. One light-year is about 6 trillion miles (9 trillion km). That is a 6 with 12 zeros behind it!

5 0
3 years ago
Overloaded methods must be differentiated by: Select one: a. method name b. data type of arguments c. method signature d. None o
Zarrin [17]

Answer:

b. data type of arguments

Explanation:

One of the ways to overload a method is using different type of arguments. Let's say we have a method that finds and returns two integer values

public int sumValues(int num1, int num2){

       return num1 + num2;

}

We can overload this method by passing double values as arguments

public double sumValues(double num1, double num2){

       return num1 + num2;

}

5 0
2 years ago
Other questions:
  • HELP ME PLZZ FFFAAASSSTTTT
    8·2 answers
  • To arrange data in alphabetical order quickly, you can _____ the data.
    7·2 answers
  • Many people object to increased cybersecurity because _____.
    12·2 answers
  • 1. Write a recursive method to determine if a character is in a list of characters in O(logN) time. Mathematically prove (as we
    13·1 answer
  • Define<br>output<br>devices<br>.<br>Give<br>any<br>three<br>examples<br>.<br>3.​
    8·2 answers
  • Consider the following code snippet:
    13·1 answer
  • Typically, a DVD has how many times more capacity than a CD?
    12·1 answer
  • Which of the following statements about wide area networks are true? Select 3 options.
    11·1 answer
  • Who is the father of computer?​
    14·1 answer
  • Project stem test 3 answers
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!