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

Slides:



Advertisements
Similar presentations
Solve problems with Java code Algorithms with Java.
Advertisements

#include void main() { float x = 1.66, y = 1.75; printf(%f%f,ceil(x), floor(y)); }
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Discrete Maths Objective to describe the Big-Oh notation for estimating the running time of programs , Semester 2, Running Time of.
Recursive Descent Technique CMSC 331. UMBC 2 The Header /* This program matches the following A -> B { '|' B } B -> C { '&' C } C -> D { '^' D } D ->
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Program Looping EE2372 Software Design I Dr. Gerardo Rosiles.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
BNF <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Programming In C++ Spring Semester 2013 Practice 2 Programming In C++, Practice By Umer Rana.
Fundamental of C programming
DS:Lab-1 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Spring Semester 2013 Lecture 5
WEEK 13 Class Activities Lecturer’s slides.
Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
What is shape function ? shape function is a function that will give the displacements inside an element if its displacement at all the node locations.
void count_down (int count) { for(i=count; i>1; i--) printf(" %d\t", count); } printf("A%d\n", count); if(count>1) count_down(count-1); printf("B%d\n",
By Senem Kumova Metin 1 DATA TYPES. by Senem Kumova Metin 2 DATA TYPE? …… x; // DECLARATION OF VARIABLE X printf(“Do you want to go on? \n”) printf(“Please.
Sort the given string, without using string handling functions.
C Intro.
 2007 Pearson Education, Inc. All rights reserved. Structs as Function Arguments and Results  Arrays – Pass by referance  Struts – the same way as the.
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
Solution April 13, #include int main( void ) { int salaries[ 11 ] = { 0 }; /*total salary */ int sales; /* sales per karyawan */ double salary;
Growing Arrays in C By: Victoria Tielebein CS 265- Spring 2011.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 5 – Recursive Funtions From Deitel’s “C” Book 5.13Recursion 5.14Example Using Recursion: The Fibonacci.
C FAQ’S Collected from the students who attended technical round in TCS recruitment.
 Introduction Introduction  Types of Function Types of Function  Library function Library function  User defined function User defined function 
MAHENDRAN CHAPTER 6. Session Objectives Explain Type of Functions Discuss category of Functions Declaration & Prototypes Explain User Defined Functions.
Reading the data from the input devices and displaying the results on the screen are the two main tasks of any program. To perform these tasks user friendly.
SNPL1 GAUSS ELIMINATION & BACK SUBSTITUTION GAUSS ELIMINATION & BACK SUBSTITUTION Dayun Yu Seungmuk Ji.
Agenda  Perform Quiz#2 (20 Minutes)  Functions / Continued … –Functions - Definition –Types of Functions: Functions that do not accept or return a value.
Return function Random function Recursion function Function in C 1.
Topics to be covered  Introduction to array Introduction to array  Types of array Types of array  One dimensional array One dimensional array  Declaration.
Chapter 5 – Functions II Outline Recursion Examples Using Recursion: The Fibonacci Series.
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");
Passing Structure to function.  structure to function structure to function  Passing structure to function in C Passing structure to function in C 
Selection-making Decisions Selection allows you to choose between two or more possible program flow --- it lets you make decisions in your program. Examples.
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.
Definition of function Types of Function Built-in User Defined Catagories of Function No argument No return value Argument but No return value No argument.
Decision Making It is used to change the order of the program based on condition. Categories: – Sequential structure – Selection structure – Iteration.
Lecture 4 Function example. Example1 int max (int a, int b) { int c; if (a > b) c = a; else c = b; return (c); } void main ( ) {int x, y; cin>>x>>y; cout.
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.
BY ILTAF MEHDI (MCS, MCSE, CCNA)1. INSTRUCTOR: ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) BY ILTAF MEHDI (MCS, MCSE, CCNA)2 Chapter No: 04 “Loops”
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
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.
Data Types and Input Output in C. Size of a Character in C #include int main() { char ch; ch = 'A'; printf("ch = %c\n",ch); printf("size of char = %d.
Overloading Unary Operators
C Functions -Continue…-.
Sum of natural numbers class SumOfNaturalNumbers {
Decisions Chapter 4.
Condition Statements.
CHAPTER 7 RECURSIVE FUNCTION
مبانی کامپیوتر و برنامه سازی
Recursion.
Tejalal Choudhary “C Programming from Scratch” Function & its types
توابع. توابع دليل استفاده از تابع اجتناب از نوشتن تكراري خطوط يكسان در يك برنامه ساختار برنامه بهتر و قابل فهم ميشود استقلال زير روالها از تابع main.
מבני נתונים ויעילות אלגוריתמים
Điều kiện Chương 5.
Recursion Prog #include <stdio.h> #include<conio.h> main()
Java Lesson 36 Mr. Kalmes.
A function with one argument
Functions with arrays.
Recursive GCD Demo public class Euclid {
Relational, Logical, and Equality Operators
Arrays I Handling lists of data.
Functions Extra Examples.
Recursion Yikes!. Recursion Yikes! What is this? RACECAR.
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 Descenting 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 Descenting 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); }