Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

* i need help with 2 programs * 1. Enter the first side (as a decimal): 10.5 Ent

ID: 3806422 • Letter: #

Question

* i need help with 2 programs *

1.

Enter the first side (as a decimal): 10.5
Enter the second side (as a decimal): 15.5
The area is 162.75
The perimeter is: 52.0

Should the user choose the circle (3)

Enter the radius (decimal): 30.2
The area is:2,865.2557
The circumference is: 189.752

Should the user choose the triangle:

Enter the height of the triangle (decimal): 3.0
Enter the base of the triangle (decimal): 4.0
The area is: 6.0
The perimeter is 12.0

When deciding on the data type to use for your sides (rectangle), radius (circle), base and height (triangle) consider how you will use them and the numeric types that will be used in the computations.

Declare PI as a named constant and assign it the value of 3.14159 at the time of declaration.

Notice that the example above strongly suggests that your program will require a series of interactions with the user in order to gather data for each set of shape calculations.

Assume you will be working with a right triangle (a triangle of 90 degrees).

Some calculations you may find useful:

for the perimeter of a rectangle:
perimeter = 2 * (side1 + side2)

for the circumference of a circle:
circumference = 2 * PI * radius

for the perimeter of a triangle:
perimeter = base + height + hypotenuse

to find the hypotenuse of the right triangle:
hyptenuse2 = base2 + height2

2.

A variation on the number sequence Fibonacci envisioned to solve that problem -- 0, 1, 1, 2, 3, 5... -- has become associated with definitions of beauty and ratios unrelated to mathematics (but as it turns out, very useful in Computer Science).

The problem reads:

Prompt the user for the number of values in Fibonacci the user wants to see. The sequence may be produced by using the last two values in the sequence to produce the next value. Start the sequence with 0 and 1. The next value in the sequence would be 1 (= 0 + 1). The next value would be 2 (= 1 + 1) and the value following would be 3 (= 1 + 2).

A typical session might look like this...

How many Fibonacci numbers do you want to see? 9

The Fibonacci sequence for 9 numbers is...
0, 1, 1, 2, 3, 5, 8, 13, 21

Explanation / Answer

First Program
-----------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <math.h>

#define PI 3.14159
void main()
{
int input;
float side1, side2, height, base, rad;

printf("%s ", "1.Rectangle");
printf("%s ", "2.Circle");
        printf("%s ", "3.Right angle Triangle");
        printf("%s", "Enter your choice:");
        scanf("%d", &input);
        switch (input)
{
  case 1:
   printf("%s", "Enter the first side (as a decimal): ")
   scanf("%f", &side1);
   printf("%s", "Enter the second side (as a decimal): ")
   scanf("%f", &side2);
                        printf("%s %.2f ", "The area is ", side1 * side2)
   printf("%s %.2f ", "The perimeter is ", 2 * (side1 + side2))
  case 2:
   printf("%s", "Enter the radius (decimal): ")
   scanf("%f", &rad);
                        printf("%s %.2f ", "The area is ", PI * rad * rad)
                        printf("%s %.2f ", "The perimeter is ", 2 * PI * rad)
  case 3:
   printf("%s", "Enter the height of the triangle (decimal): ")
   scanf("%f", &height);
   printf("%s", "Enter the base of the triangle (decimal): ")
   scanf("%f", &base);
                        printf("%s %.2f ", "The area is ", (1/2) * height * base)
                        printf("%s %.2f ", "The perimeter is ", height + base + sqrt(height * height + base * base))
                       
}
}

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

Second Program
-------------------------------------------------------------------------------------------------------------
#include <stdio.h>

int main()
{
   int n, first = 0, second = 1, next, i;

   printf("How many Fibonacci numbers do you want to see?");
   scanf("%d",&n);
   printf("The Fibonacci sequence for %d numbers is... ", n);

   for ( i = 0 ; i < n ; i++ )
   {
      if ( i <= 1 )
         next = i;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }
      printf("%d %s ",next, " , ");
   }

   return 0;
}