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
Trava [24]
4 years ago
11

Write a for loop that assigns summedvalue with the sum of all odd values from 1 to usernum. assume usernum is always greater tha

n or equal to 1.
Mathematics
1 answer:
Lapatulllka [165]4 years ago
5 0
// Input value is usernum.
// This code snippet sums 1 + 3 + 5 + ... + usernum
//  The answer is stored in the variable summedvalue.

N = (int) (usernum+1)/2;    // maximum number of integers to be summed
int *v = malloc(N*sizeof(int));     //  allocate storage for array v

// Calculate the number of loop counts and assign array v..
count = 0;
k = 1;
while (1) {
       if (k>usernum) {   //  do not extend v beyond usernum
          break;
          }
       v(count) = k;        //  assign an odd integer to v, including usenum
       count++;
       k += 2;                //  k is an odd number
       if k>usernum {          // handle usernum as odd or even
          k = usernum;
          } 
 }
n = count;          // the size of array v.

// Calculate the sum in a for loop
summedvalue  = 0;               // initialize summedvalue
for (i=0; i<=n; i++) {
     summedvalue += v(i);
    }


You might be interested in
What is the equation to 1 + 1
timurjin [86]

Answer:

2

Step-by-step explanation:

3 0
4 years ago
Which list of numbers is ordered from greatest to least? A. –215, 214, 2.23, –2 B. 214, 2.23, –2, –215 C. –2, –215, 214, 2.23 D.
slamgirl [31]

Answer:b

Step-by-step explanation:

4 0
3 years ago
Help help help quizziz fast please
NikAS [45]

Answer:

2!

Step-by-step explanation:

the number by the X is the slope

6 0
3 years ago
company 2 charges 4600$ for the first 550 feet of fence and 29 for each additional feet.find the cost if company 2 completes the
Maru [420]

Answer:

I love you 6.78

Step-by-step explanation:

You have to love yourself

- 5x

-6 x 45

6.78

4 0
4 years ago
The crime scene with dimensions below is being taped off. If each roll of tape
Thepotemich [5.8K]

Answer:

4

Step-by-step explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • If a raffle has a winning prize of $100 and each ticket costs $5 with a total of 500 tickets sold, which equation would calculat
    6·2 answers
  • Over the summer, for every 12 okra seeds Dana planted, 7 grew into plants. If he planted 156 okra seeds, how many grew into plan
    11·1 answer
  • A line passes through the origin and the point (3,5) what is the slope of the line?
    8·1 answer
  • Helpppp in 8 asap plzz
    7·1 answer
  • What is 25 x 10^6?<br> Someone help me I don't understand this at all!<br> Thanks
    11·1 answer
  • How would you show your work in the question "A fence is being built around a rectangular garden that is 8 1/2 feet by 6 1/3. Fe
    10·1 answer
  • I need it done assap<br><br>Will give brainly!!!
    15·2 answers
  • Someone please help me I need help
    7·1 answer
  • X&lt;7, x=6<br> True or false<br><br> Help please
    14·2 answers
  • 9. Which correctly describes the root of the following cubic equation?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!