answer.
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
natima
18 days ago
11

7.7 LAB: Using a while loop countdown Write a program that takes in an integer in the range 10 to 100 as input. Your program sho

uld countdown from that number to 0, printing the count each of each iteration.After ten numbers have been printed to the screen, you should start a newline.The program should stop looping at 0 and not output that value. I would suggest using a counter to count how many items have been printed out and then after 10 items, print a new line character and then reset the counter. important: Your output should use " %3d " for exact spacing and a space before and after each number that is output with newlines in order to test correctly.
Computers and Technology
1 answer:
Natasha_Volkova [897]18 days ago
3 0

Answer:

The code is implemented in Java

  1. public class Main {
  2.    public static void main(String[] args) {
  3.        int count = 0;
  4.        Scanner stream = new Scanner(System.in);
  5.        System.out.print("Enter a number between 10 and 100: ");
  6.        int num = stream.nextInt();
  7.        while(num > 0){
  8.            if(count % 10!= 0){
  9.                System.out.printf("%3d", num);
  10.            }else{
  11.                System.out.println();
  12.                System.out.printf("%3d", num);
  13.            }
  14.            count++;
  15.            num--;
  16.        }
  17.    }
  18. }

Explanation:

To start, initiate a counter named count and set it to zero (Line 3).

Then, instantiate a Scanner object, requesting the user to enter a number from 10 to 100 (Line 4-6).

Implement a while loop that continues as long as the countdown number remains above zero (Line 8). Then, introduce an if statement to determine if the counter is a multiple of 10. If it is not, display the current num; if it is, start a new line before displaying the current num (Line 9 -14).

After each iteration, increase the count by one and decrease num by one (Line 15 -16).

You might be interested in
A 1.17 g sample of an alkane hydrocarbon gas occupies a volume of 674 mL at 28°C and 741 mmHg. Alkanes are known to have the gen
Natasha_Volkova [897]

Answer:

C3H8

Explanation:

Step 1:

Relevant details from the question are noted below:

Mass of the alkane is 1.17g

Volume (V) = 674 mL

Temperature (T) = 28°C

Pressure (P) = 741 mmHg.

Gas constant (R) = 0.08206 atm.L/Kmol

Step 2:

Convert to the appropriate units.

For Volume:

1000mL = 1L

So, 674mL = 674/1000 = 0.674L

For Temperature:

Temperature in Kelvin = Temperature in Celsius + 273

Temperature in Celsius = 28°C

Temperature in Kelvin = 28°C + 273 = 301K

For Pressure:

760mmHg = 1atm

So, 741 mmHg = 741/760 = 0.975atm

Step 3:

Calculate the moles of the alkane.

The moles of the alkane can be found using the ideal gas equation, presented below:

Volume (V) = 0.674L

Temperature (T) = 301K

Pressure (P) = 0.975atm

Gas constant (R) = 0.08206 atm.L/Kmol

Number of moles (n) =?

PV = nRT

n = PV /RT

n = (0.975 x 0.674)/(0.08206x301)

n = 0.0266 moles

Step 4:

Calculate the alkane’s molar mass.

Mass of alkane = 1.17g

Number of moles = 0.0266moles

Molar Mass =?

Number of moles = Mass/Molar Mass

Molar Mass = Mass/Number of moles

Molar Mass of alkane = 1.17/0.0266 = 44g/mol

Step 5:

Determine the molecular formula of the alkane.

This is based on:

The general formula for alkanes is CnH2n+2

To find the molecular formula, we start with n = 1, 2, 3, etc., until we find the molar mass of 44.

When n = 1

CnH2n+2 = CH4 = 12 + (4x1) = 16g/mol

When n = 2

CnH2n+2 = C2H6 = (12x2) + (6x1) = 30g/mol

When n = 3

CnH2n+2 = C3H8 = (12x3) + (8x1) = 44g/mol

It can be observed that for n equal to 3, the molar mass is 44g/mol.

Thus, the molecular formula of the alkane is C3H8.

7 0
29 days ago
Mia is disappointed with how her latest video games are playing on her computer; the images are slow
amid [805]

Answer:

She is expressing dissatisfaction with her images loading slowly and lagging; she should consider acquiring a new GPU since, well, it's quite evident that GPU stands for graphics processing unit, which makes the connection clear.

8 0
10 days ago
CodeLab Question
Rzqust [894]

Response:

I am not familiar with coding languages, but I can demonstrate how you might do it in Python

myAlarm():

   arm = True

   code = "secret message"

myAlarm()

main():

deactivate = input(">>> ")

if deactivate = myAlarm.code:

  arm = False

I still feel a bit unclear about the question.

(I work as a game developer and code daily)

3 0
11 days ago
CHALLENGE ACTIVITY 2.15.1: Reading and outputting strings. Write a program that reads a person's first and last names, separated
Harlamova29_29 [932]

Response:

#include <iostream>

using namespace std;

int main()

{

   string Fname, Lname;

   cout << "Please enter your first name " <<"Please enter your last name" <<endl;

   cin>>Fname>>Lname;

   cout<<Lname<<", "<<Fname<<endl;

   return 0;

}

Clarification:

This code is coded in the C++ programming language. To begin with, two string variables are declared, namely Fname and Lname for the first and last names, respectively. The C++ cout function is utilized to ask users for their inputs, while the cin function takes in user inputs and stores them in the corresponding variables. The cout operator (<<) arranges the output in accordance with the specification given in the question

8 0
22 days ago
The factorial of a nonnegative integer n is written n ! (pronounced "n factorial") and is defined as follows: n ! = n · (n - 1)
Harlamova29_29 [932]
Here are the programs. I have written C++ and Python scripts:

a)

C++

#include<iostream>  

using namespace std;  

int factorial(int num)  {  

   if (num == 0)  

       return 1;  

   return num * factorial(num - 1);  }    

int main()  {  

   int integer;

   cout<<"Enter a non negative integer: ";

   cin>>integer;

   cout<< "Factorial of "<< integer<<" is "<< factorial(integer)<< endl;  }

Python:

def factorial(num):  

   if num == 0:  

       return 1

   return num * factorial(num-1)  

integer = int(input("Enter a non negative integer: "))  

print("Factorial of", integer, "is", factorial(integer))

b)

C++

#include <iostream>  

using namespace std;

double factorial(int number) {  

if (number == 0)  

 return 1;  

return number * factorial(number - 1); }  

 

double estimate_e(int num){

    double e = 1;

    for(int i = 1; i < num; i++)

     e = e + 1/factorial(i);

     cout<<"e: "<< e; }  

 

int main(){

int term;

cout<<"Enter a term to evaluate: ";

cin>>term;

estimate_e(term);}

Python:

def factorial(number):  

   if number == 0:  

       return 1

   return number * factorial(number-1)  

def estimate_e(term):

   if not term:

       return 0

   else:

       return (1 / factorial(term-1)) + estimate_e(term-1)

number = int(input("Enter how many terms to evaluate "))

print("e: ", estimate_e(number))

c)

C++

#include <iostream>

using namespace std;

int main(){

   float terms, sumSeries, series;

   int i, number;

   cout << " Input the value of x: ";

   cin >> number;

   cout << " Input number of terms: ";

   cin >> terms;

   sumSeries = 1;

   series = 1;

   for (i = 1; i < terms; i++)      {

       series = series * number / (float)i;

       sumSeries = sumSeries + series;     }

   cout << " The sum  is: " << sumSeries << endl;  }  

Python    

def ePowerx(number,terms):

   sumSeries = 1

   series =1

   for x in range(1,terms):

       series = series * number / x;

       sumSeries = sumSeries + series;

   return sumSeries    

num = int(input("Enter a number: "))

term=int(input("Enter a number: "))

print("e^x: ",ePowerx(num,term))

Explanation:

a)

The program includes a factorial method that takes a number as an argument and calculates its factorial using recursion. For instance, if number = 3

The base case occurs at  if (number == 0)

and the recursion is handled with return number * factorial(number - 1);  

With number = 3 not equaling zero, the function calls itself recursively to get the factorial of 3

return 3* factorial(3- 1);

3 * factorial(2)

3* [2* factorial(2- 1) ]

3 * 2* [ factorial(1)]

3 * 2 * [1* factorial(1- 1) ]

3 * 2 * 1* [factorial(0)]

At this point at factorial(0), the base condition is satisfied as number==0, so factorial(0) returns 1

The resulting output is:

3 * 2 * 1* 1

yielding 6

So, the final program output will be

Factorial of 3 is 6

b)

The estimate_e method takes a number, termed as num, which signifies the term to estimate the mathematical constant e

The for loop extends through each term. For example, if num is set to 3

Then the core statement:

e = e + 1/factorial(i);  

The preceding calculation works as:

e = 1 + 1/1! +1/2!

Since the term count is 3

Initially, e is set to 1

i is initialized at 1

Inserting this into the calculation gives us:

e = 1 + 1/factorial(1)

The factorial function computes and returns 1, as the factorial of 1 is 1. Thus,

e = 1 + 1/1

This results in e = 2

Proceeding to the next iteration, where i = 2 and e = 2, we calculate e = 2 + 1/factorial(2)

Thus, e = 2 + 1/2 results in e = 2.5

Following to the next iteration with i = 3, we have e = 3 + 1/factorial(3)

This yields e = 3 + 1/6 resulting in approximately e = 3.16666

Therefore, the output is:

e: 3.16666

c)

This program calculates the sum of a series based on the formula:

e^x = 1 + x/1! + x^2/2! + x^3/3! +...

The for loop iterates according to the number set for terms. Assuming x is 2, and the number of terms is set to 3, the series would read:

e^2 = 1 + 2/1! + 2^2/2!

In this setup: number = 2 and terms = 3

Initial values for series and sumSeries are both 1

Starting with i equal to 1, the update statement series = series * number / (float)i; applies as follows:series = 1 * 2 /1 results in series = 2

Then, for sumSeries, we have sumSeries = sumSeries + series; Outputs sumSeries as 1 + 2, yielding 3

Continuing to the next iteration: i=2, with series = 2 and sumSeries = 3, we recalculate as series = 2 * 2/2 imposing series = 2 again. Thus, we find: sumSeries = 3 + 2 giving a final sumSeries value of 5

After the loop concludes, the result shows the value of sumSeries, leading finally to the output value of 5
8 0
13 days ago
Other questions:
  • print_pattern() prints 5 characters. Call print_pattern() twice to print 10 characters. Example output: ***** ***** in python
    7·1 answer
  •  How does critically analyzing technology add value to interactions with people in personal and professional contexts?
    9·2 answers
  • When performing actions between your computer and one that is infected with a virus which of the following offers no risk becomi
    5·1 answer
  • CHALLENGE ACTIVITY 2.1.2: Assigning a sum. Write a statement that assigns total_coins with the sum of nickel_count and dime_coun
    11·1 answer
  • Form the recurrence relations (RRs) for the number of vertices and the number of edges of a hypercube of n dimensions, Hn. Solve
    13·1 answer
  • Assume that the following variables have been properly declared and initialized.
    12·1 answer
  • A developer writes a trigger on the Account object on the before update event that increments a count field. A workflow rule als
    12·1 answer
  • You work for a car rental agency and want to determine what characteristics are shared among your most loyal customers. To do th
    10·1 answer
  • Sara is writing a program to input her monthly phone bills and output the month name and amount for the month with maximum amoun
    7·1 answer
  • Write a program that prompts the user to enter three cities and displays them in ascending order. Here is a sample run: Enter th
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!