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
tatuchka [14]
3 years ago
10

The factorial of an integer N is the product of the integers between 1 and N, inclusive. Write a while loop that computes the fa

ctorial of a given integer N.
Computers and Technology
1 answer:
alexdok [17]3 years ago
3 0

the function and loop will be

def factorial(x):

   total = 1

   if x != 1 and x != 0:

       for i in range(x,1,-1):

           total *= i

   return total

You might be interested in
Assume the existence of an UNSORTED ARRAY of n characters. You are to trace the CS111Sort algorithm (as described here) to reord
makvit [3.9K]

Answer:

class Main {

  public static void main(String[] args) {

      char arr[] = {'T','E','D','R','W','B','S','V','A'};

      int n = arr.length;

      System.out.println("Selection Sort:");

      System.out.println("Iteration\tArray\tComparisons");

      long comp1 = selectionSort(arr);

      System.out.println("Total comparisons: "+comp1);

      System.out.println("\nInsertion Sort:");

      System.out.println("Iteration\tArray\tComparisons");

      long comp2 = insertionSort(arr);

      System.out.println("Total Comparisons: "+comp2);

      System.out.println("\nOverall Total Comparisons: "+(comp1+comp2));

  }

  static long selectionSort(char arr[]) {

      // applies selection sort for n/2 elements

      // returns number of comparisons

      int n = arr.length;

      long comparisons = 0;

 

      // One by one move boundary of unsorted subarray

      for (int i = n-1; i>=n-n/2; i--) {

              // Find the minimum element in unsorted array

              int max_idx = i;

              for (int j = i-1; j>=0; j--) {

                      // there is a comparison everytime this loop returns

                      comparisons++;

                      if (arr[j] > arr[max_idx])

                              max_idx = j;

              }

              // Swap the found minimum element with the first

              // element

              char temp = arr[max_idx];

              arr[max_idx] = arr[i];

              arr[i] = temp;

              System.out.print(n-1-i+"\t");

              printArray(arr);

              System.out.println("\t"+comparisons);

      }

     

      return comparisons;

  }

  static long insertionSort(char arr[]) {

      // applies insertion sort for n/2 elements

      // returns number of comparisons

      int n = arr.length;

      n = n-n/2;   // sort only the first n/2 elements

      long comparisons = 0;

      for (int i = 1; i < n; ++i) {

          char key = arr[i];

          int j = i - 1;

          /* Move elements of arr[0..i-1], that are

                  greater than key, to one position ahead

                  of their current position */

          while (j >= 0) {

              // there is a comparison everytime this loop runs

              comparisons++;

              if (arr[j] > key) {

                  arr[j + 1] = arr[j];

              } else {

                  break;

              }

              j--;

          }

          arr[j + 1] = key;

          System.out.print(i-1+"\t");

          printArray(arr);

          System.out.println("\t"+comparisons);

      }

      return comparisons;

  }  

  static void printArray(char arr[]) {

      for (int i=0; i<arr.length; i++)

          System.out.print(arr[i]+" ");

  }

}

Explanation:

Explanation is in the answer.

6 0
3 years ago
What is the name of the method generated when you double-click a button named btnprocess in the form designer?
Ilia_Sergeevich [38]

When you double-click a button with the name btnprocess in the form designer, a method with the name BtnProcess Click is created.

<h3>What is the BTN group?</h3>
  • Bootstrap's "Button Groups" class, often known as "btn-group," is used to arrange groups of buttons (without spaces) vertically or horizontally.
  • The button group class's fundamental syntax is as follows, with each button having a separate "btn" class.
  • In Bootstrap, a class with the name "btn-group" is used to group together a set of buttons either vertically or horizontally.

The button group class's fundamental syntax is as follows, with each button having its own "btn" class.

Class="btn-group" in the div

Click the button type="button" class="btn"> button.

</div>

To learn more about BtnProcess, refer to:

brainly.com/question/809966

#SPJ4

5 0
1 year ago
What are the most popular/up-and-coming social media applications?
tekilochka [14]
How about vine camera? or musically?
7 0
2 years ago
Read 2 more answers
A nonpipelined system takes 300ns to process a task. The same task can be processed in a 5-segment pipeline with a clock cycle o
Vladimir79 [104]

Answer:

Pipelined architecture is 1.667 times more speedy than non pipelined architecture.

Explanation:

There are five stages to to complete an instruction to execute in pipeline architecture. as

Stage 1:  Instruction Fetch

Stage 2: Instruction Decode

Stage 3: Execute

Stage 4: Memory Access

Stage 5 : Write Back

The pipeline architecture processed instruction as given below. Each Stage take 1 clock cycle, which is represented as CC.

                Stage 1           Stage 2         Stage 3         Stage 4            Stage 5

I1:              1cc                  2cc                 3cc                4cc                   5cc

I2              2cc                 3cc                  4cc               5cc                   6cc

I3              3cc                  4cc                 5cc              6cc                    7cc

I4              4cc                 5cc                  6cc              7cc                    8cc

each four Instructions set takes 8 Clock Cycles.

I5              9cc                  10cc                11cc               12cc                 13cc

I6              10cc                 11cc                  12cc             13cc                 14cc

I7              11cc                  12cc                 13cc              14cc                 15cc

I8              12cc                 13cc                  14cc              15cc                16cc

.

.

.

I97:             193cc            194cc              195cc              196cc               197cc

I98             194cc             195cc             196cc               197cc               198cc

I99            195cc             196cc              197cc              198cc               199cc

I100         196cc                197cc             198cc            199cc                 200cc

<u>Pipelined architecture Time Calculation</u>

So in pipeline architecture 100 instructions takes 200 clock cycles to execute.

1 Clock Cycle time period is = 60ns.

200 Clock Cycle =  60ns * 200 = 12000 ns

<u>Non Pipelined architecture Time Calculation</u>

1 task Time period= 300ns

100 task time period = 100 * 300 =  30000 ns

The difference between pipelined and non pipelined architecture time period is = 30000 - 12000 = 18000 ns

<u>Speedup ratio</u>

<em>Speed up ratio= 30000/18000 =  1.667</em>

7 0
3 years ago
Research the topic of legal and ethical behaviors or dilemmas related to technology. Identify five topics of concern and briefly
max2010maxim [7]

Answer:

if you push alt and f4 at the same time it will automatically put the right answer.

Explanation:

7 0
2 years ago
Other questions:
  • A name given to a spot in memory is called:
    5·1 answer
  • Assume that LO and HI have already been assigned as constants with LO &lt; HI, and x has been declared as DWORD in the data segm
    7·1 answer
  • _____ are special combinations of keys that tell a computer to perform a command.
    9·2 answers
  • Using a cell phone while operating a motor vehicle is considered distraction because
    8·1 answer
  • In terms of object-oriented programming, after a class is defined,
    11·1 answer
  • Brake fluid should be checked __________.
    8·2 answers
  • Which option is referred to by the Reports Due tag?
    7·1 answer
  • The acronym pies is used to describe improvised explosive devices (ied) components. pies stands for:
    13·2 answers
  • How many sets of number do both Hex and RGB values have?
    10·1 answer
  • What is abbreviation of the computer​
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!