0% found this document useful (0 votes)
34 views4 pages

Recursion: MD Ankushavali (Emb1) DATE:06-02-2018

Recursion is a powerful technique that defines a problem in terms of itself by dividing it into smaller, similar subproblems. A recursive function calls itself until a terminating condition is reached. For example, a factorial function uses recursion to calculate the factorial of a number by multiplying it by the factorial of the number minus one. Enumeration defines user data types with named integral constants to make programs more readable. Bitwise operators like AND, OR, XOR are used to set, clear, or complement single bits in binary representations.

Uploaded by

KALYAN
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)
34 views4 pages

Recursion: MD Ankushavali (Emb1) DATE:06-02-2018

Recursion is a powerful technique that defines a problem in terms of itself by dividing it into smaller, similar subproblems. A recursive function calls itself until a terminating condition is reached. For example, a factorial function uses recursion to calculate the factorial of a number by multiplying it by the factorial of the number minus one. Enumeration defines user data types with named integral constants to make programs more readable. Bitwise operators like AND, OR, XOR are used to set, clear, or complement single bits in binary representations.

Uploaded by

KALYAN
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
You are on page 1/ 4

MD ANKUSHAVALI(EMB1)

DATE:06-02-2018
RECURSION
Recursion is a powerful technique of writing a complicated algorithm in
an easy way. According to this technique a problem is defined in terms of itself.
The problem is solved by dividing it into smaller problems, which are similar in
nature to the original problem. These smaller problems are solved their
solutions are applied to get the final solution of our original problem.
To implement recursion technique in programming, a function should be
capable of calling itself this facility is available in C. The function that call itself
(inside function body) again and again is known as a recursive function. In
recursion the calling function and the called function are same.
For example:
main()
{
..........
rec ( ) ;
.........
}
rec ( )
{
.........
...........
rec ( ); -------- recursive call
..............
}

Before writing a recursive function for a problem we should consider these points
1. We should be able to define the solution of the problem in terms of a similar
type of smaller problem.
At each step we get closer to' the final' solution of our original problem.
2. There should be a terminating condition to stop recursion.
Program : Factorial by using recursion
#include<stdio.h>
int main()
{
int num,res;
printf(“enter the number:”);
scanf(“%d”,&num);
res=fact_recursion(num)
printf(“%d”,res);
}
int fact_recursion(int num)
{
int res=1;
if (num==1)
return res;
else
res=num*fact_recursion(num-1);
retunn res;
}

Input:5
Output:120

Program : Printing the numbers

#include<stdio.h>
void print_numbers(int num);
int main()
{
int num;
printf(“enter a num:”);
scanf(“%d”,&num);
printf_numbers(int num);
return 0;
}
void print_numbers(int num)
{
if(num==0)
return;
print_num(num-1); //interchange these two lines and check
printf(“%d”,num); //the output
return;
}

Output:
5,1
2
3
4
5
ENUM (Enumeration)
Enumeration (or enum) is a user defined data type in C. It is mainly used to
assign names to integral constants, the names make a program easy to read and
maintain.

// An example program to demonstrate working


// of enum in C
#include<stdio.h>

enum week{Mon, Tue, Wed, Thur, Fri, Sat, Sun};

int main()
{
enum week day;
day = Wed;
printf("%d",day);
return 0;
}

Bitwise operators Significance

Bit Operator Bit Result


X & 1 X
X | 1 1
X ^ 1 X’

Setting a single bit


#include<stdio.h>
Short int set_bit(int pos);
Int main()
{
Short int va1,res;
V1=0x4567;
Res= Short int set_bit(int pos); Return 0;
}
Short int set_bit(int pos)
{
Res= val|(1<<pos);
Return res;
}
Clearing a single bit
Res=val&(~(1<<pos))
Complementing a single bit
Use XOR (^)
Check the status
AND operation with 1

No of Class room programs Total


7 7

You might also like