Showing posts with label Series. Show all posts
Showing posts with label Series. Show all posts

TO FIND FIBONACCI SERIES USING C PROGRAM

How TO FIND FIBONACCI SERIES USING C PROGRAM.


#include<stdio.h>
int main(){
  int n,r,ncr;
  printf("Enter any two numbers->");
  scanf("%d %d",&n,&r);
  ncr=fact(n)/(fact(r)*fact(n-r));
  printf("The NCR factor of %d and %d is %d",n,r,ncr);
  return 0;
}
 int fact(int n){
  int i=1;
  while(n!=0){
      i=i*n;
      n--;
  }
  return i;
 }

C Program To Generating Fibonacci Series Using Recursion

How to write a C Program To Generating Fibonacci Series Using Recursion in C Programming Language ?

Solution For C Program :

/*C Program To Generating Fibonocci Series Using Recursion.*/

#include<stdio.h>
void main()
{
int a, b, j;
int fib(int);
printf("\nEnter N'th Number : "); scanf("%d", &a);
printf("\nPrinting Values of the Fibonacci Series :\n");
for(j = 0; j < a - 1; j++)
{
b = fib(j);
printf("%d,", b);
}
}
int fib(int n)
{
int x, y;
if(n == 0 || n == 1) return (1);
else
{
x = fib(n - 1);
y = fib(n - 2); return(x + y);
}
}

You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C program to add first seven terms of the following series using a for loop: (1/1!) + (2/2!) + (3/3!) + .....

How to Write a C Program to add first seven terms of the following series using a for loop:

(1/1!) + (2/2!) + (3/3!) + .....

This C Program to add first seven terms of the following series using a for loop: (1/1!) + (2/2!) + (3/3!) + .....


  1. #include<stdio.h>
  2. main()
  3. {
  4. float result, temp_calc, num, temp, factorial;
  5. result=0;
  6. for (num=1; num<=7; num++)
  7. {
  8. for (temp=1, factorial=1; temp<=num; temp++)
  9. {
  10. factorial = factorial*temp;
  11. temp_calc = (num/factorial);
  12. }
  13. result=result+temp_calc;
  14. }
  15. printf("(1/1!) + (2/2!) + (3/3!) + (4/4!) + (5/5!) + (6/6!) + (7/7!) = %f", result);
  16. }
C Program to Fibonacci Sequence

C Program to Fibonacci Sequence

A series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.

Leonardo Bonacci (c. 1170 – c. 1250)—known as Fibonacci, and also Leonardo of Pisa, Leonardo Pisano Bigollo, Leonardo Fibonacci—was an Italian mathematician, considered to be "the most talented Western mathematician of the Middle Ages".

Fibonacci popularized the Hindu–Arabic numeral system to the Western World primarily through his composition in 1202 of Liber Abaci (Book of Calculation).[6] He also introduced to Europe the sequence of Fibonacci numbers which he used as an example in Liber Abaci.

Fibonacci sequence   Fibonacci number

19th century statue of Fibonacci in Camposanto, Pisa.
Liber Abaci posed, and solved, a problem involving the growth of a population of rabbits based on idealized assumptions. The solution, generation by generation, was a sequence of numbers later known as Fibonacci numbers. Although Fibonacci's Liber Abaci contains the earliest known description of the sequence outside of India, the sequence had been noted by Indian mathematicians as early as the sixth century.
In the Fibonacci sequence of numbers, each number is the sum of the previous two numbers. Fibonacci began the sequence not with 0, 1, 1, 2, as modern mathematicians do but with 1,1, 2, etc. He carried the calculation up to the thirteenth place (fourteenth in modern counting), that is 233, though another manuscript carries it to the next place: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377. Fibonacci did not speak about the golden ratio as the limit of the ratio of consecutive numbers in this sequence.

Solution:

This C Program Find the Fibonacci Sequence of a Number in C Program. nth Number is enter through keyboard.

  1. #include <stdio.h>
  2. int fibo(int);
  3. int main()
  4. {
  5.     int num;
  6.     int result;
  7.     printf("Enter the nth number in fibonacci series: ");
  8.     scanf("%d", &num);
  9.     if (num < 0)
  10.     {
  11.         printf("The fibonacci of a negative number is not possible.\n");
  12.     }
  13.     else
  14.     {
  15.         result = fibo(num);
  16.         printf("The %d number in fibonacci series is %d\n", num, result);
  17.     }
  18.     return 0;
  19. }
  20. int fibo(int num)
  21. {
  22.     if (num == 0)
  23.     {
  24.         return 0;
  25.     }
  26.     else if (num == 1)
  27.     {
  28.         return 1;
  29.     }
  30.     else
  31.     {
  32.         return(fibo(num - 1) + fibo(num - 2));
  33.     }
  34.    
  35. }

C Program to Add-Subtract Series 5-10+15

How to write a C Program to Add-Subtract Series 5-10+15 in C Programming Language ?


Solution:
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int n, sum=0,i,number=5,sign=1;
  5.     for(i=1; i<=9; i++) {
  6.         sum = sum + number*sign;
  7.         number = number + 5;
  8.         sign = sign*(-1);
  9.     }
  10.     printf("%d", sum);
  11. }

C Program to Add Series 1+3+5

How to write a C Program to Add Series 1+3+5 in C Programming Language ?


Solution:
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int n, sum=0,i;
  5.     for(i=1; i<=9; i=i+2) {
  6.         sum = sum+i;
  7.     }
  8.     printf("%d", sum);
  9. }