Recursion is used on large problems that can be broken down into smaller, repetitive problems. It is especially implement on branches and large or complex iterative approach.
Write a C Program to Find Factorial User given using Recursion : About factorial: 5! = 5!x4!x3!x2!x1! = 120 Code: #include<stdio.h> void main() { int facto(int); int n,b; printf("Enter a range of factorial:\n"); scanf("%d",&n); b=facto(n); printf("\nThe factorial of %d is %d",n,b); } int facto(int n) { if(n==1) return n; else n=n*facto(n-1); return n; } Output:
Swap Two Number: Tips: 1.Take three variables. 2.Take two inputs from user. 3.Assign variables one by one each other. Code: main() { int a,b,s; printf("Enter two number two swap:\n"); scanf("%d%d",&a,&b); printf("\nyou decide:\na=%d and b=%d",a,b); getch(0); s=a; a=b; b=s; printf("\nThe swap number is: a=%d and b=%d",a,b); getch(); } Output: Please comment!
Recursion is used on large problems that can be broken down into smaller, repetitive problems. It is especially implement on branches and large or complex iterative approach.
ReplyDelete