0% found this document useful (0 votes)
2 views2 pages

Function & Recursion

The document provides two C programming examples: one for calculating the area of a rectangle using a function and returning the value to the main function, and another for generating the Fibonacci series using recursion. The first program prompts the user for the rectangle's dimensions and outputs the area, while the second prompts for a number and computes the Fibonacci series. Both examples illustrate basic function usage and recursion in C programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Function & Recursion

The document provides two C programming examples: one for calculating the area of a rectangle using a function and returning the value to the main function, and another for generating the Fibonacci series using recursion. The first program prompts the user for the rectangle's dimensions and outputs the area, while the second prompts for a number and computes the Fibonacci series. Both examples illustrate basic function usage and recursion in C programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

2000320130071 Date

Function and Recursion


1 Write a program to print area of rectangle using & return the vlue to main
function.
#include<stdio.h>

int area(int a,int b

return a*b;

void main()

{ int a,b;

printf("Enter the dimensions of Rectangle\n");

printf("Enter the length and breadth\n");

scanf("%d%d",&a,&b);

area(a,b);

printf("Area = %d",area(a,b));

2. Write a program to print the Fibonacci series using recusion.


#include<stdio.h>

int fab_rec(int n)

{ if(n==1 || n==2)
{ return n-1;

} else

return fab_rec(n-1) + fab_rec(n-2);

}}

void main()

{ int n,c;

printf("Enter the number\n");

scanf("%d",&n);

c=(fab_rec(n-1) + fab_rec(n-2));

printf("The fibonacci series of %d is %d\n",n,c);

You might also like