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
monitta
2 years ago
14

Convert the given for loop to while loop and find the output of the program assuming the

Computers and Technology
1 answer:
Kruka [31]2 years ago
6 0

Answer:

Explanation:

num = int (input ("Enter a value"))

sum =0

count=0

i = 1

while i < num:

 if i%2 == 0:

        count += 1

        sum += i

        i += 1

 i += 1

print(sum)

print(count)

The output assuming num is 15 would be

56

7

You might be interested in
Create a Rational number class in Java using the same style as the Complex number class created in class.(The in class example c
Elis [28]

Answer:

Explanation:

/*

*    This program adds, subtracts, multiplies, and divides two rational numbers.

*/

public class Main {

  //Main method

   public static void main(String[] args) {

       Rational a = new Rational(3, 4);   // input for first rational number

       Rational b = new Rational(2 , 5);   // input for second rational number

       System.out.println(a + " + " + b + " = " + a.add(b));

       System.out.println(a + " - " + b + " = " + a.sub(b));

       System.out.println(a + " * " + b + " = " + a.mul(b));

       System.out.println(a + " / " + b + " = " + a.div(b));

   }

}

class Rational {

   public Rational(int num, int den) {

      numerator = num;

      denominator = den;

     

      //ensures a non-zero denominator

      if (den == 0)

          den =1;

     

      //stores a negative sign in numerator

      if (den < 0) {

          num = num * -1;

          den = den * -1;

      }

   }

   //return numerator

   public int getNumerator() {

     

      return numerator;

   }

 

   //return denominator

   public int getDenominator() {

     

      return denominator;

   }

 

   //return reciprocal method

   public Rational reciprocal() {

     

      return new Rational(denominator, numerator);

   }

   /*   Addition Class

    *        Find common denominator by multiplying the denominators

    *        Store number values (numerator / common denominator) as num1 and num2

    *        Sum both numbers

    */

   public Rational add(Rational r2) {

      int comDen = denominator * r2.getDenominator();

      int num1 = numerator * r2.getDenominator();

      int num2 = r2.getNumerator() * denominator;

      int sum = num1 + num2;

      return new Rational (sum, comDen);

   }

   //Subtraction Class - same implementation as Addition Class

   public Rational sub(Rational r2) {

   

     int comDen = denominator * r2.getDenominator();

     int num1 = numerator * r2.getDenominator();

     int num2 = r2.getNumerator() * denominator;

     int difference = num1 - num2;

     return new Rational (difference, comDen);

  }

   

  /*   Multiplication Class

   *        Multiply numerator with r2 numerator

   *        Multiply denominator with r2 denominator

   */

  public Rational mul(Rational r2) {

   

     int num = numerator * r2.getNumerator();

     int den = denominator * r2.getDenominator();

     return new Rational (num, den);

  }

  /*   Divide Class

   *        Multiply number by r2 reciprocal

   */

  public Rational div(Rational r2) {

      return mul (r2.reciprocal());

  }

  /*   toString Method

   *        Returns rational number as a string - in parenthesis if a fraction

   */

  public String toString() {

     

      return (((numerator == 0) ? "0" : ( (denominator == 1) ? numerator + "": "(" + numerator + "/" + denominator + ")")));

 

      /* Logic for toString method

      * if (num == 0) {

              return "0";

          } else {

              if (denominator == 1){

                  return numerator;

              } else {

                  return numerator + "/" + denominator;

              }

      */

   }

  // Declare variables

  private int numerator, denominator;

 

}

output

(3/4) + (2/5) = (23/20)                                                                                                                                      

(3/4) - (2/5) = (7/20)                                                                                                                                      

(3/4) * (2/5) = (6/20)                                                                                                                                      

(3/4) / (2/5) = (15/8)                                                                                                                                      

6 0
2 years ago
Define a function compute_gas_volume that returns the volume of a gas given parameters pressure, temperature, and moles. Use
jeyben [28]

Question:

Define a function compute_gas_volume that returns the volume of a gas given parameters pressure, temperature, and moles. Use the gas equation PV = nRT, where P is pressure in Pascals, V is volume in cubic meters, n is number of moles, R is the gas constant 8.3144621 ( J / (mol*K)), and T is temperature in Kelvin.

Answer:

This solution is implemented in C++

double compute_gas_volume(double P, double T, double n){

   double V = 8.3144621 * n * T/P;

   return V;

}

Explanation:

This line defines the function, along with three parameters

double compute_gas_volume(double P, double T, double n){

This calculates the volume

   double V = 8.3144621 * n * T/P;

This returns the calculated volume

   return V;

}

To call the function  from the main, use:

<em>cout<<compute_gas_volume(P,T,n);</em>

<em />

<em>Where P, T and n are double variables and they must have been initialized</em>

5 0
3 years ago
Sort short_names in reverse alphabetic order.
tangare [24]

lst = short_names.split()

print(sorted(lst,reverse = True))

6 0
2 years ago
Which of the following is something that would NOT appear in the Reviewing pane?
Sophie [7]

Answer:

A

Explanation:

7 0
2 years ago
The field on which records are sorted is called the composite primary key.A. TrueB. False
Gemiola [76]

Answer: TRUE

Explanation: Composite is simply used to refer to the existence of more than one event or pattern. The composite primary key as related to database management query refers to the synergy or combination of more than one field or column of a specified table which is used in sorting or accurate identification of a record. When attributes are combined, that is more than one, it assists in narrowing down the returned records such that records which are close and exclusive to the options specified are returned. Usually, the more the number of columns which makes uo the case mpoaite keys, the more unique and well sorted our returned output is.

4 0
3 years ago
Other questions:
  • Describe the indicators and hazards of a metal deck roof fire in an unprotected steel joist warehouse as well as the techniques
    6·1 answer
  • When employees are hired, they agree to only use cell phones during breaks. How would you classify this?
    8·2 answers
  • What does this say:<br> √ans
    6·2 answers
  • What type of social engineering attack uses email to direct you to their their website where they claim you need to update/valid
    6·2 answers
  • Which of the following statements is true about a file stream?
    5·1 answer
  • Given a String variable response that has already been declared, write some code that repeatedly reads a value from standard inp
    10·1 answer
  • Write a function called missing_letters that takes a string parameter and returns a new string with all the letters of the alpha
    7·1 answer
  • How does cryptocurrency exchange software works?
    14·1 answer
  • Which of the following would be least effective?
    10·1 answer
  • Write a loop that reads positive integers from console input, printing out those values that are even, separating them with spac
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!