using cc write loops to control Our first lab will be simila

using c/c++, write loop(s) to control
Our first lab will be similar to the examples discussed in class, covering programming concepts in loop, function, and recursion. It includes the following tasks: Using C/C++, write loop(s) to control and output a star pattern as follows: giving a integer N (use can to assign N), first, you need to print a triangle with N rows, the star number in each row equals the row number (e.g. the 1^st row has 1 star, the N^th row has N stars). Then output a reverse triangle with (N-1) row. the first row of the reverse triangle has (N-1) stars, and the last row of the reverse triangle has 1 star. All stars are center aligned, and the pattern is in a diamond shape. E.g. when N is 3, you will print the following star pattern In main(), declare a variable N, input an integer (positive and less than 30) from standard input (keyboard); based on the value of N, use a loop to calculate the N^th Fibonacci number and print the result. Define a recursive function to calculate Fibonacci numbers. In main(), assign N with an integer (positive and less than 20) from standard input. Based on the value N, call the recursive function and output the N^th Fibonacci number: Fibonacci(N) = Fibonacci(N-1) + Fibonacci(N-2) following specifications will be expected for each of your projects in this class: An empty project file must be created first, and then you will create new file and header files. Add comments at the beginning of the program, and add description

Solution

#include <stdio.h>
int main()
{
   int i, j ,gap, Number, k=0;
printf(\"Enter the number of Number: \");
scanf(\"%d\",&Number);
for(i=1; i<=Number; ++i, k=0)
{
for(gap=1; gap<=Number-i; ++gap)
{
printf(\" \");
}

while(k != 2*i-1)
{
printf(\"* \");
++k;
}

printf(\"\ \");
}
  
for(i=Number; i>=1; --i)
{
for(gap=0; gap < Number-i; ++gap)
printf(\" \");
for(j=i; j <= 2*i-1; ++j)
printf(\"* \");
for(j=0; j < i-1; ++j)
printf(\"* \");

printf(\"\ \");
}
//getch();
return 0;
}

using c/c++, write loop(s) to control Our first lab will be similar to the examples discussed in class, covering programming concepts in loop, function, and rec

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site