Assignment 6

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Assignment 6

1) Write a program to find factorial of number using


the function.

#include<stdio.h>
float fact(int n);
int main()
{
int n;
printf("Enter the positive integer:");
scanf("%d",&n);
printf("\n The factorial of given number %d is = %f",n,fact(n));
return 0;
}

float fact(int n)
{
if(n>=1)
{
return n*(fact(n-1));
}
else
{
return 1;
}
}

Output:
Enter the positive integer:5

The factorial of given number 5 is = 120.000000


2) Write a program to implement Fibonacci series using
function.

#include<stdio.h>
int Fibo(int);
int main()
{
int n, i = 0, c;
printf("Enter number of terms to be printed:");
scanf("%d",&n);
printf("Fibonacci series\n");
for ( c = 1 ; c <= n ; c++ )
{
printf("%d\n", Fibo(i));
i++;
}
return 0;
}

int Fibo(int n)
{
if ( n == 0 )
return 0;
else if ( n == 1 )
return 1;
else
return ( Fibo(n-1) + Fibo(n-2) );
}

Output:
Enter number of terms to be printed:10
Fibonacci series
0
1
1
2
3
5
8
13
21
34

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy