Recursion Prog #include <stdio.h> #include<conio.h> main()

Slides:



Advertisements
Similar presentations
Recursion Prog #include <stdio.h> #include<conio.h> main()
Advertisements

Sort the given string, without using string handling functions.
Algorithm & Flow Charts Decision Making and Looping Presented By Manesh T Course:1090 CS.
/* program to find area of a ring */ #include int main() { float a1,a2,a,r1,r2; printf("Enter the radius : "); scanf("%f",&r1); a1 = 3.14*r1*r1; printf("Enter.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
LAB 10.
More Questions 1) Write a C program to read a matrix A of size nXn and two arrays X and Y of size n and calculate XA-Y?
MAHENDRAN CHAPTER 6. Session Objectives Explain Type of Functions Discuss category of Functions Declaration & Prototypes Explain User Defined Functions.
SNPL1 GAUSS ELIMINATION & BACK SUBSTITUTION GAUSS ELIMINATION & BACK SUBSTITUTION Dayun Yu Seungmuk Ji.
Write a C program to pass an array containing age of person to a function. This function should find average age and display the average age in main function.
Data structure and c K.S. Prabhu Letterer All Deaf Educational Technology.
PASSING VALUE TO A FUNCTION # CALL BY VALUECALL BY VALUE # CALL BY REFERENCECALL BY REFERENCE STORAGE CLASS # AUTOAUTO # EXTERNALEXTERNAL # STATICSTATIC.
Topics to be covered  Introduction to array Introduction to array  Types of array Types of array  One dimensional array One dimensional array  Declaration.
PRESENTATION ON SEARCHING SEARCHING Searching is the method to find element from the list of the elements. If element is found then it.
Chapter 6: Control Structures Computer Programming Skills Second Term Department of Computer Science Foundation Year Program Umm Alqura.
UniMAP SemI-09/10EKT120: Computer Programming1 Week 5 – Functions (1)
Example #include void main() { int a,b,c,n; clrscr(); printf("\nEnter the value of a,b:"); scanf("%d%d",&a,&b); printf("\nMENU"); printf("\n1.ADD\n2.SUB\n3.MULTIPLY\n0.EXIT");
FUNCTIONS A function is a set of instructions that can perform a specific task accordingly. A function is a program that performs a specific task according.
Chinese Proverb says……... Advantages void main( ) { int n, k, i ; printf(“\n Enter number:-”); scanf(“%d”, &n); for(i=2 ; i
Decision Making It is used to change the order of the program based on condition. Categories: – Sequential structure – Selection structure – Iteration.
Strings program. C Program to Check if a given String is Palindrome #include void main() { char string[25], reverse_string[25] = {'\0'}; int i, length.
Strings program. C Program to Check if a given String is Palindrome #include void main() { char string[25], reverse_string[25] = {'\0'}; int i, length.
Rray Programs. Insert and element in the given position of the Array rray.
Write a C program to pass an array containing age of person to a function. This function should find average age and display the average age in main function.
POINTERS IN C Pointer Basics, Pointer Arithmetic, Pointer to arrays and Pointer in functions.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
UNIT - 3 ARRAYS AND STRINGS. Array An Array is a collection of similar data items, that are stored under a common name. Types –One-Dimensional array –Two-Dimensional.
Functions The fruitful & parameterized functions.
Algorithm & Flow Charts Decision Making and Looping
Explain Declaration,Initialization of Array Explain Types of Array One Dimensional,Two Dimensional and Multi Dimensional Array Explain Arrays.
MAHENDRAN. Session Objectives Explain Declaration,Initialization of Array Explain Types of Array One Dimensional,Two Dimensional and Multi Dimensional.
Recursive. Recursive F(n) = F(n-1) + F(n-2) n! = (n-1)! x n C(m,n) = C(m-1,n-1)+C(m-1,n)......
The Repetition control structure using while loop.
Control Structures Introduction
WHILE, DO-WHILE AND FOR LOOPS
EKT120: Computer Programming
LESSON 3 IO, Variables and Operators
FUNCTIONS.
Week 4 – Repetition Structures / Loops
Condition Statements.
Exercises on String Operations
CHAPTER 7 RECURSIVE FUNCTION
Functions Dr. Ashish Sasankar. In programming, a function is a segment that groups code to perform a specific task. A C program has at least one function.
مبانی کامپیوتر و برنامه سازی
CHƯƠNG II CÁC HÀM NHẬP XUẤT
Visit for more Learning Resources
מבוא כללי למדעי המחשב תרגול 2
Recursive functions.
Programming in C Part 2.
Chapter 5 POINTERs.
توابع ورودي-خروجي.
Computer Programming Summer 2017
INC 161 , CPE 100 Computer Programming
Engr 0012 (04-1) LecNotes
מ- C++ ל- C קרן כליף.
מבני נתונים ויעילות אלגוריתמים
Điều kiện Chương 5.
CSC215 Homework Homework 04 Due date: Oct 14, 2016.
Loops in C.
שיעור רביעי: פונקציות, מבוא לרקורסיה
A function with one argument
UNIT - 3 Noornilo Nafees.
Control Statements_2.
Introduction to Problem Solving and Programming
In C Programming Language
Character Arrays char string1[] = “first”;
Course Outcomes of Programming In C (PIC) (17212, C203):
Recursive example 1 double power(double x, int n) // post: returns x^n
6-лекция Турбо Си тілі элементтері.
Visit for more Learning Resources
Presentation transcript:

Recursion Prog #include <stdio.h> #include<conio.h> main() Addition of 2 nos #include <stdio.h> #include<conio.h> main() { int add(int pk,int pm); int k = 2; int i; int m = 3; clrscr(); i = add(k,m); printf("i = %d\n",i); getch(); } int add(int addk,int addm){ if(addm==0) return(addk); else return(1+add(addk,addm-1));

Recursion Prog #include<conio.h> #include <stdio.h> Power function #include<conio.h> #include <stdio.h> int main() { double power(double x, int n); double x = 0.0; int n = 0; clrscr(); printf("%lf",power(3,2)); getch(); } double power(double x, int n) { if(n == 0) return 1.0; else return x * power( x , n - 1 );

Recursion Prog #include<conio.h> #include <stdio.h> Even sum #include<conio.h> #include <stdio.h> void main() { int sum(int,int ); int total; total=sum(2,4); clrscr(); printf("%d",total); getch(); } int sum(int i,int n){ static int even=0; if(i<=n){ even=even+i; sum(i+2,n); //calling same function return even;

Recursion Prog #include<string.h> void reverse(char [],int b); Reverse String #include<string.h> void reverse(char [],int b); void main() { char a[26]; int len; clrscr(); printf("enter string "); Scanf(“%s”,a); len=strlen(a); reverse(a,len); getch(); } void reverse(char a[],int len) { if(len==0) printf("%c",a[len]); else reverse(a,len-1); }

Recursion Prog #include<conio.h> #include <stdio.h> Reverse Number #include<conio.h> #include <stdio.h> int sum=0,r; void main() { int reverse(int); int num,rev; clrscr(); printf("\nEnter a number :"); scanf("%d",&num); rev=reverse(num); printf("\nAfter reverse the no is :%d",rev); getch(); } Int reverse(int num) { if(num>0) r=num%10; sum=sum*10+r; reverse(num/10); } else{ return sum;

Recursion Prog void main() { long term(int); int i,n; clrscr(); Fibnocci Series void main() { long term(int); int i,n; clrscr(); printf(“Enter Limit”); scanf("%d",&n); printf("\nThe Series is :”); for(i=1;i<=n;i++) printf(" %ld ",term(i)); } getch(); long term(int n) { if(n==1) return(0); else if(n==2||n==3) return 1; else return(term(n-1)+term(n-2)); return 0; }

Recursion Prog main() { int i,n; void pat(int); clrscr(); Print Pattern main() { int i,n; void pat(int); clrscr(); for(i=1;i<=10;i++) pat(i); } getch(); void pat(int n) { if(n<1) printf("\n"); else printf("%d ",n); n=n-1; mult(n); }

Recursion Prog main() { int i,n; void de(int); clrscr(); de(20); Print Nos in Descending ordre main() { int i,n; void de(int); clrscr(); de(20); getch(); } void de(int n) { if(n==0) return(0); else printf("\n %d",n); de(n-1); }

Recursion Prog main() { int i,n; void de(int); clrscr(); de(20); Print EVEN Nos in Descending ordre main() { int i,n; void de(int); clrscr(); de(20); getch(); } void de(int n) { if(n==0) return(0); else printf("\n %d",n); de(n-2); }