Chapter - 10: Strings

Write a program that generates and prints the Fibonacci words of order 0 through 5. If f(0) = "a", f(1) = "b", f(2) = "ba", f(3) = "bab", f(4) = "babba", etc.


D
Sections
5
Exercises

A

B

C

D

E

F

1

2

3

4

5

6

7

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
	char x[50] = "a", z[50];
	char y[50] = "b";
	int i;
	for (i = 0; i <= 5; i++)
	{
		printf("%s\t", x);//printing x
		strcpy(z, x);/*copying x into z*/
		strcpy(x, y);/*copying y into x*/
		strcat(y, z);/*adding (concatinating) z in y*/
	}
	_getch();
	return 0;
}

© 2020 Garbage Valuegarbage value logo