Fibonacci Series: Fibonacci sequence or Fibonacci Series is a series where the next number is the sum of pervious two numbers. The first two terms of the Fibonacci sequence is 0 followed by 1.
For Example
The Fibonacci sequence or Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21 etc. The first two numbers of fibonacci series are 0 and 1.
Lets understan using This Image:
There are two ways to write the fibonacci series program:
Fibonacci Series without recursion
Fibonacci Series using recursion
Fibonacci Series in C without recursion
Let's see the fibonacci series program in c without recursion.
#include<stdio.h>
#include<conio.h>
void main()
{
int n1=0,n2=1,n3,i,number;
clrscr();
printf("Enter the number of elements:");
scanf("%d",&number);
printf("\n%d %d",n1,n2);//printing 0 and 1
for(i=2;i<number;++i)//loop starts from 2 because 0 and 1 are already printed
{
n3=n1+n2;
printf(" %d",n3);
n1=n2;
n2=n3;
}
getch();
}
Output:
Enter the number of elements:15
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
Fibonacci Series using recursion in C
Let's see the fibonacci series program in c using recursion.
#include<stdio.h>
#include<conio.h>
void printFibonacci(int n){
staticint n1=0,n2=1,n3;
if(n>0){
n3 = n1 + n2;
n1 = n2;
n2 = n3;
printf("%d ",n3);
printFibonacci(n-1);
}
}
void main(){
int n;
clrscr();
printf("Enter the number of elements: ");
scanf("%d",&n);
printf("Fibonacci Series: ");
printf("%d %d ",0,1);
printFibonacci(n-2);//n-2 because 2 numbers are already printed
getch();
}
Output:
Enter the number of elements:15
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
C language is a generic,
procedural computer programming language. In 1972, in order to transplant
and develop the UNIX operating system, Dennis Ritchie in Bell telephone lab
design and development of the C language.
C language is a widely used
computer language, which is as popular as the Java programming language, both
of which are widely used among modern software programmers.
The current latest C language
standard for C11, before its C language standard for C99.
This tutorial is designed
for software programmers who need to learn C from scratch. This tutorial
will give you an idea of the C language to enhance your own level of
expertise.
Before you read this tutorial, you need to
know the knowledge:
Before you start this
tutorial, you need a basic understanding of computer programming
terminology. A basic understanding of any programming language will help
you understand the C language programming concepts and help speed your learning
progress.
Compile / execute C program
Examples:
#include
< stdio.h
>
Int
main (
)
{ / * my first C program * /
printf
( " Hello, World! \ N " ) ;
return 0 ;
}
Example Analysis:
·All C language
programs need to include the main () function. The code
starts from the main () function.
·/
* ... * / for annotations.
·Printf
() is used to format
the output to the screen. The printf () function is declared
in the "stdio.h" header file.
·Stdio.h is a header file (standard input and
output header file), #include is a preprocessing command, used
to introduce the header file. When the compiler encounters the printf
() function , a compile error occurs if the stdio.h header
file is not found .
·Return
0; statement is
used to indicate exit procedure.
C language is a common high-level language, originally
designed by Dennis Ritchie in the Bell Labs for the development of UNIX
operating system. The C language was first implemented in 1972 on the DEC
PDP-11 computer.
In 1978, Brian Kernighan and Dennis Ritchie produced
the first publicly available description of C, now known as the K & R
standard.
UNIX operating system, C compiler, and almost all UNIX
applications are written in C language. For a variety of reasons, the C
language has now become a widely used professional language.
·Easy to learn.
·Structured language.
·It produces efficient programs.
·It can handle the underlying activities.
·It can be compiled on a variety of computer platforms.
About C
·The C language was invented for the purpose of writing a UNIX
operating system.
·C language is based on the B language, B language is probably
introduced in 1970.
·The C language standard was developed in 1988 by the American
National Standards Institute (ANSI).
·As of 1973, the UNIX operating system was written entirely in C
language.
·At present, C language is the most widely used system
programming language.
·Most of the advanced software is implemented using the C
language.
·Today's most popular Linux operating system and RDBMS
(Relational Database Management System: relational database management system)
MySQL are written in C language.
Why use C?
C language was
originally used for system development work, especially the composition of the
operating system procedures. Since the code generated by the C language
runs almost as fast as the code written in the assembly language, the C
language is used as the system development language. Here are a few
examples of using C:
·operating system
·Language compiler
·Assembler
·text editor
·printer
·Network drive
·Modern procedures
·database
·Language interpreter
·Physical tools
C program
A C language program,
which can be 3 lines or millions of lines, can be written in one or
more text files with the extension ".c" ,
for example, hello.c . You can use "vi" , "vim" or
any other text editor to write your C program.
This tutorial assumes
that you already know how to edit a text file and how to write the source code
in the program file.
C11
C11 (also known as
C1X) refers to ISO standard ISO / IEC 9899: 2011, is the latest C language
standard. Prior to its C language standard for C99.
New features
·Alignment normalization
(including the _Alignas notation, the alignof operator, the aligned_alloc
function, and the <stdalign.h> header file).
·_Noreturn function tag, similar
to gcc __attribute __ ((noreturn)).
·_Generic keywords.
·Multithreading support,
including:
_Thread_local storage type identifier, <threads.h> header file, which
contains the thread creation and management functions.
_Atomic type modifier and <stdatomic.h> header file.
·Enhanced Unicode
support. Enhanced Unicode support based on the C Unicode Technical Report
ISO / IEC TR 19769: 2004. Including the char16_t and char32_t data types for
UTF-16 / UTF-32 encoding, providing the header file <uchar.h> containing
the unicode string conversion function.
·Removed the gets () function,
using a new, more secure function gets_s () instead.
·Added a border check function
interface that defines new security functions such as fopen_s (), strcat_s (),
and so on.
·Added more floating point
processing macros (macros).
·Anonymous structure / consortium
support. This gcc already exists, C11 will be introduced into the
standard.
·Static assertions, _ Static_assert
(), are processed after interpreting #if and #error.
·New fopen () mode, ("...
x"). Similar to POSIX in the O_CREAT | O_EXCL, in the file lock is
more commonly used.
·Added the quick_exit () function
as a third way to terminate the program. You can do the least cleanup when
exit () fails.