Starting from:

$30

CSCI2500-Lab 1 Loops and Printf in C Solved

Write a program that asks the user for a positive odd integer n, then builds a triangle as shown in the example below. Implement this using nested for loops.

What is n? 7

*

***

*****

*******

If you didn’t do so in the first place, write a function to build this triangle. To stop program execution, use -1 as the sentinel value to end the program (and let the user know this). Next, write another function to accomplish the same results, but use printf() to achieve the formatting and at most one loop.

Given the previous problem, you next will have your program calculate the area of each triangle. Assume the triangle is an isosceles triangle with the given base of length n and a height equal to the number of rows used to build the triangle. Using printf() to display exactly two digits of precision.

Fibonacci
The Fibonacci sequence is calculated recursively by summing the previous two values of the sequence, i.e., fib(n)=fib(n-1)+fib(n-2). Assume that this sequence starts with 0 and 1 as its first two elements.

Write a program (using long and not int for fib) that asks the user for a non-negative integer, then computes its Fibonacci number using a recursive function.

Run your program on larger and larger numbers. Does it take a long time to compute? Is there any way to speed this computation up and keep the recursion? Can you speed this computation up by removing the recursion?

More products