Question

In: Computer Science

write code with proper comments for ever step the code should be in form of pseudocode                            &

write code with proper comments for ever step the code should be in form of pseudocode                                   

To Print Triangle of any size, by taking size as input.
To Print Triangle of any size, by taking size as input. If size is 4 then triangle is:
To calculate Factorial of any number.
To calculate the power of any given number.
To Print Table of Any Number up till 10: as shown in this figure.
for a program which reads 10 integers from the user, and output the largest value
from input numbers.

Solutions

Expert Solution

Triangle:

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

  

            // loop to print the number of spaces before the star

            for (int j = rows; j >= i; j--) {

cout<<" ";

            }

              // loop to print the number of stars in each row

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

cout<<"*";

            }

//new line

        }

Factorial:

int factorial(int n)

{

    if (n == 0)

    return 1;

    return n * factorial(n - 1);

}

Power:

int power(int a, int b)

{

    if (b == 0)

        return 1;

    else if (b % 2 == 0)

        return power(a, b / 2) * power(a, b / 2);

    else

        return a* power(a, b / 2) * power(a, b / 2);

}

Table:

    int n = 5; // Take any input number

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

        cout << n << " * " << i << " = "  << n * i << endl;

Largest:

int a[10];

int i;

int greatest;

printf("Enter ten values:");

//Store 10 numbers in an array

for (i = 0; i < 10; i++)

{ scanf("%d", &a[i]); }

//Assume that a[0] is greatest

greatest = a[0];

for (i = 0; i < 10; i++) {

if (a[i] > greatest)

{ greatest = a[i]; }

}

At the end greatest will have the largest number


Related Solutions

Given the below pseudocode, write the proper code that implements it using MARIE's assembly language:               ...
Given the below pseudocode, write the proper code that implements it using MARIE's assembly language:                    Input a number and store it in X; if X > 1 then    Y := X + X;    X := 0; endif; Y := Y + 1; Output the value of Y; N.B: You should include the MARIE code in your Answer, with an explanation of each instruction in your code beside it. Example:              Subt One         /Subtract 1 from AC Add a...
write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
write the code in MATLAB with comments and show the inputs and results of the code...
write the code in MATLAB with comments and show the inputs and results of the code for the question below. Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds that was recorded using your phone), then take Fourier transform of the signal (probably FFT).
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an...
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an earthquake is in the range [0, 3), “medium” if M is in the range [3, 6), “large” if M is in the range [6, 9) and “epic” if M is greater than or equal to 9, where M is input by a user via the keyboard. (in c++)
1. Write code in mips that will play battleships. Include comments in code on what each...
1. Write code in mips that will play battleships. Include comments in code on what each part is doing.
write the pseudocode and code to solve the following: you are given a list. determine the...
write the pseudocode and code to solve the following: you are given a list. determine the sum of all the elements in the list without using the built in puthon function sum(). Take your code and create your own function and name it my_sum_algo() which will return the sum of numbers PS please write comments in the code for my understanding, and please write jn jn PYTHON 3 languge. Thank you, have a great day !
Write a pseudocode for the following code: /*every item has a name and a cost */...
Write a pseudocode for the following code: /*every item has a name and a cost */ public class Item {    private String name;    private double cost;    public Item(String name, double cost) {        this.name = name;        this.cost = cost;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public double getCost() {        return cost;...
**Add comments to existing ARM code to explain steps** Question that my code answers: Write an...
**Add comments to existing ARM code to explain steps** Question that my code answers: Write an ARM assembly program to calculate the value of the following function: f(y) = 3y^2 – 2y + 10 when y = 3. My Code below, that needs comments added: FunSolve.s LDR R6,=y LDR R1,[R6] MOV R2,#5 MOV R3,#6 MUL R4,R1,R1 MUL R4,R4,R2 MUL R5,R1,R3 SUB R4,R4,R5 ADD R4,R4,#8 st B st y DCD 3
Code needed in C++ (nOT IN STEP BY STEP EITHER)    Write a recursive function that...
Code needed in C++ (nOT IN STEP BY STEP EITHER)    Write a recursive function that computes the sum of the digits in an integer. Use the following function header: int sumDigits(int n) For example, sumDigits(234) returns 2 + 3 + 4 = 9. Write a test program that prompts the user to enter an integer and displays its sum.
Using pseudocode or C++ code, write a function to compute and return the product of two...
Using pseudocode or C++ code, write a function to compute and return the product of two sums. The first is the sum of the elements of the first half of an array A. The second is the sum of the elements of the second half of A. The function receives A and N ≥ 2, the size of A, as parameters. (in c++)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT