C Program : Let us look at the output for our program shared on 19/07/2023

in c-programming •  last year 

Welcome back,
In today's blog we will see the output of our recently shared program. The detailed explanation of the program was already shared yesterday so those who want to see that can visit the blog shared yesterday.

Let us look at the program now,

Screenshot 2023-07-19 081512.png

Screenshot 2023-07-19 081524.png

Screenshot 2023-07-19 081538.png

You can copy the program from below :

#include <stdio.h>

// Function to generate Fibonacci sequence iteratively
void fibonacciIterative(int n) {
int prev = 0, current = 1, next;
printf("Fibonacci Sequence (Iterative):\n");
printf("%d ", prev);
for (int i = 1; i <= n; i++) {
printf("%d ", current);
next = prev + current;
prev = current;
current = next;
}
printf("\n");
}

// Function to generate Fibonacci sequence recursively
int fibonacciRecursive(int n) {
if (n <= 1)
return n;
return fibonacciRecursive(n - 1) + fibonacciRecursive(n - 2);
}

int main() {
int num;
printf("Enter the number of terms to generate in the Fibonacci sequence: ");
scanf("%d", &num);

// Generate Fibonacci sequence iteratively
fibonacciIterative(num);

// Generate Fibonacci sequence recursively
printf("Fibonacci Sequence (Recursive):\n");
for (int i = 0; i <= num; i++) {
printf("%d ", fibonacciRecursive(i));
}
printf("\n");

return 0;
}

Now let us run this program to find the output of our program. I use online C compiler to run these program so that people who will run can use the same compiler and there is no issue because of the compiler change with them.

here is how the output will look like.

image.png

If you also want to learn basics and start your C programming journey then find a teacher today for free on Youtube.

I learnt alot from a teacher who teaches c in hindi and if you are finding someone who teaches in hindi then this person will definitely help you.

Source

I am happy to call myself a trader and small programmer at the same time now.

Happy trading and keep learning what you love.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE BLURT!