Question

Write a program with loops that compute a.The sum of all even numbers between 2 and...

Write a program with loops that compute

a.The sum of all even numbers between 2 and 100 (inclusive).

b.The sum of all squares between 1 and 100 (inclusive).

c.All powers of 2 from 20 up to 220.

d.The sum of all odd numbers between a and b (inclusive), where a and b are inputs.

Note*: For part d, enter 3 and 21 as input

Output should be:

a. 2550
b. 338350
c.

1.0
2.0
4.0
8.0
...
1048576.05

d. 120

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Here is the code and screenshots, please let me know if you have any doubts/ clarifications. Go through the comments for better understanding of the code. I am providing you a file called Even_sum.c. If you are on Unix/ Linux platform then use gcc Even_sum.c -lm for compiling the code and ./a.out for running the program. Thank you, Good Luck!!!

Even_sum.c

#include<stdio.h> #include<math.h> int main() { int sum = 0; // Displays the sum for (int i = 2; i<=100; i++) { if ((i%2)==0){ sum = sum + i; } } printf("%d\n", sum); // Displays the sum of all squares between 1-100 int sumOfAllNumbers = 0; for (int i = 1; i<=100; i++) { sumOfAllNumbers = sumOfAllNumbers + i*i; } printf("%d\n", sumOfAllNumbers); // Powers of 2 from 20 to 220 double power = 0; for (int i = 0; i<=20; i++) { power = pow(2,i); printf("%0.1f\n", power); } // sum of all the odd numbers between a & b int a = 3; int b = 21; int sumOfAllOdds = 0; for (int i=a; i<=b; i++){ if (i%2 !=0){ sumOfAllOdds = sumOfAllOdds + i; } } printf("%d\n", sumOfAllOdds); return 1; }

---------------------------------------------------------------------------------------------------------------------

O/P Screenshot

Even_sum.c Screenshots

Add a comment
Know the answer?
Add Answer to:
Write a program with loops that compute a.The sum of all even numbers between 2 and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have to write a program in java which uses while loops. 1.prompt the user to...

    I have to write a program in java which uses while loops. 1.prompt the user to input two intergers: firstnum ans second numnumber. (first number must be smaller that the second number). 2. Output all the even numbers between first number and second number inclusive. 3. Output the sum of all the even number between first number and second number inclusive. 4 Output all the odd numbers between first number and second number inclusive. 5. Output the sum of all...

  • 1. In a parallel circuit: (Choose One) A.The total potential drop is the sum of all...

    1. In a parallel circuit: (Choose One) A.The total potential drop is the sum of all those in the branches. B.the potential drop is the same for each element of the circuit. C.the heat generated is the same in all the branches D.the current is the same in every branch 2. The capacitance of a parallel plate capacitor: (Choose One) A.is defined as the amount of work required to move a charge from one plate to the other. B. decreases...

  • Write a single program in java using only do/while loops for counters(do not use array pls)...

    Write a single program in java using only do/while loops for counters(do not use array pls) for the majority of the program and that asks a user to enter a integer and also asks if you have any more input (yes or no) after each input if yes cycle again, if not the program must do all the following 4 things at the end of the program once the user is finished inputting all inputs... a.The smallest and largest of...

  • Write a C program to sum up all the odd numbers between a lower limit number...

    Write a C program to sum up all the odd numbers between a lower limit number and an upper limit number provided by a user. The requirements are: First, request the user to provide a lower limit integer number and an upper limit integer number that is larger than the lower limit number, and save them in variables lowerLimit and upperLimit, respectively. If the user has entered an upper limit number (upper Limit) that is NOT larger than the lower...

  • 8.(a) Write a program that prints all of the numbers from 0 to 102 divisible by...

    8.(a) Write a program that prints all of the numbers from 0 to 102 divisible by either 3 or 7. ​ (b) Write a program that prints all of the numbers from 0 to 102 divisible by both 3 and 7 (c) Write a program that prints all of the even numbers from 0 to 102 divisible by both 3 and 7 (d) Write a program that prints all of the odd numbers from 0 to 102 divisible by both...

  • USE PYTHON: 4) [30pts] Write program which finds the followings for the given values between 150...

    USE PYTHON: 4) [30pts] Write program which finds the followings for the given values between 150 to 1000 a) How many odd numbers are between 150 and 1000 (include 150 and 1000) b) Find the sum of odd numbers which are between 150 and 1000 (include 150 and 1000) c) Find the multiplication of odd numbers which are between 150 and 1000 (include 150 and 1000) d) Find the sum of square of odd numbers which are between 150 and...

  • 2. Write an Assembly program using Super Simple CPU Instruction set that takes input 3 numbers...

    2. Write an Assembly program using Super Simple CPU Instruction set that takes input 3 numbers from the user and outputs 1 in the output box if the sum of the first two inputs is greater than the sum of the last two inputs; otherwise it outputs o in the output box. Example1, if user inputs the numbers 10, (2.0), 11, (3.0), and 1,(1,2) then the output should be 1 (since 2.0 + 3., is greater than 3.. +1,). Example...

  • write the program in VBA b. Write a program that uses a For loop to perform...

    write the program in VBA b. Write a program that uses a For loop to perform the following steps: a. Prompt the user to input two integers: firstNum and secondNum(firstNum must be less than secondNum). b. Output all odd numbers between firstNum and secondNum. c. Output the sum of all odd numbers between firstNum and secondNum. d. Output all even numbers between firstNum and second Num. e. Output the sum of all even numbers between firstNum and secondNum.

  • Write a Java program which uses a for loop to sum all the even numbers from...

    Write a Java program which uses a for loop to sum all the even numbers from 1 to 30.

  • Write a PHP program using to display all the even numbers between 1 and 100

    Write a PHP program using to display all the even numbers between 1 and 100

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT