TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

C Tutorials

C Program to generate Fibonacci sequence into rows and columns

Overview

In this post, we will develop C Program to generate Fibonacci sequence into rows and columns as output. We get the Fibonacci sequence nth term by adding the previous two terms in the sequence. i.e Fib(n) = Fib(n-1) + Fib(n-2)

C Program

//C Program Fibonacci sequence
//www.TestingDocs.com
#include 
int main()
{
 //declare variables
 int terms;
 int count, term0 = 0, term1 = 1;
 int term2 = term0 + term1;
 printf("Enter terms in the Fibonacci sequence := \n");
 scanf("%d", &terms);
 printf("\n");
 //generate the sequence
 for (count = 1; count <= terms; count++)
 {
 if(count%6 == 0)
 {
 printf("%10d ", term2);
 printf("\n");
 }
 else
 {
 printf("%10d ", term2);
 }
 term2 = term0 + term1;
 term0 = term1;
 term1 = term2;

 }
 return 0;
}

The IDE used in the program is Code:: Blocks. To download and install Code Blocks follow the link:

https://www.testingdocs.com/download-and-install-codeblocks/ For more information on Code Blocks IDE, visit the official website of Code blocks IDE: http://www.codeblocks.org/

Program Output

Related Posts

C Tutorials /

C Language Characteristics

C Tutorials /

C Program Files & Formats

C Tutorials /

C Compilers

C Tutorials /

C Pointers

C Tutorials /

C Two-Dimensional Arrays

‹ C program to find sum of even numbers from 1 to n› Hello World C Program

Recent Posts

  • Scaler Academy – An Online Learning Platform
  • Difference between PHP and JavaScript?
  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com