The Arduino Platform and C Programming (Week 2)
Write a program in C that computes and prints out the first six digits in the Fibonacci sequence. Look up the definition of the Fibonacci sequence if you don't know it. The first two numbers in the sequence are 0 and 1, but your program should compute the next four digits. Make sure your program compiles using gcc.
Then, save a text version of your program. Copy and paste the text of your program in the box here.
Then, save a text version of your program. Copy and paste the text of your program in the box here.
>>>
#include<stdio.h>
int main()
{
int i, n=6, t1=0, t2=1, nextTerm;
printf("Fibonacci Series: ");
for ( i=1; i<=n; ++i)
{
printf("%d, ",t1)
nextTerm = t1+t2;
t1 = t2;
t2 = nextTerm;
}
return 0;
}
int main()
{
int i, n=6, t1=0, t2=1, nextTerm;
printf("Fibonacci Series: ");
for ( i=1; i<=n; ++i)
{
printf("%d, ",t1)
nextTerm = t1+t2;
t1 = t2;
t2 = nextTerm;
}
return 0;
}
Comments
Post a Comment