first part of the lecture explains Recursion topic in c language.
Second half shows, what is a debugging, how to debug your program, debugging methods and debugging tool in Eclipse.
In this PPT you will learn how to use looping in python.
For more presentation in any subject please contact us on
raginijain0208@gmail.com.
You get a new presentation every Sunday at 10 AM.
Learn more about Python by clicking on given below link
Python Introduction- https://www.slideshare.net/RaginiJain21/final-presentation-on-python
Basic concept of Python -https://www.slideshare.net/RaginiJain21/python-second-ppt
Python Datatypes - https://www.slideshare.net/RaginiJain21/data-types-in-python-248466302
Python Library & Module - https://www.slideshare.net/RaginiJain21/python-libraries-and-modules
Basic Python Programs- https://www.slideshare.net/RaginiJain21/basic-python-programs
Python Media Libarary - https://www.slideshare.net/RaginiJain21/python-media-library
Types of Statements in Python Programming LanguageExplore Skilled
The slide describes the types of flow control statements in Python including conditional statement , loop statement , control statement such as break and continue .
The document discusses looping statements in C. It explains that loops allow code to be repeated without having to rewrite the code multiple times. It describes three types of loops: while, do-while, and for. It provides the syntax and an example for each loop type. It also discusses the break and continue statements that can be used within loops to terminate the loop early or skip iterations.
The document discusses different types of conditional and control statements in Python including if, if-else, elif, nested if-else, while, for loops, and else with loops.
It provides the syntax and examples of each statement type. The if statement and if-else statement are used for simple decision making. The elif statement allows for chained conditional execution with more than two possibilities. Nested if-else allows if/elif/else statements within other conditionals. While and for loops are used to repeatedly execute blocks of code, with while looping until a condition is false and for looping over sequences. The else statement with loops executes code when the loop condition is false.
This document discusses C programming concepts including data types, variables, operators, conditional statements, loops, and functions. It contains code examples to find the size of different data types, if/else statements, for/while loops, break/continue statements, and switch statements. The key points covered are:
- Using the sizeof operator to determine the size of int, float, double, char, and other variable types.
- If/else and if/else ladder conditional statements for comparing values.
- For, while, and do-while loop structures for iteration.
- Break and continue statements for early loop termination or skipping iterations.
- Switch statement for multiple conditional comparisons using case labels.
Write a program that removes line numbers in a program listing. Here is a sam...hwbloom150
Write a program that removes line numbers in a program listing. Here is a sample input:
1 print( "Enter a number: " );
2 $number = <>;
3 chomp( $number );
4
5 print "$number is an even number\n” if $number %2==0;
Your program removes all line numbers and preserves the format including empty lines.
In this PPT you will learn how to use looping in python.
For more presentation in any subject please contact us on
raginijain0208@gmail.com.
You get a new presentation every Sunday at 10 AM.
Learn more about Python by clicking on given below link
Python Introduction- https://www.slideshare.net/RaginiJain21/final-presentation-on-python
Basic concept of Python -https://www.slideshare.net/RaginiJain21/python-second-ppt
Python Datatypes - https://www.slideshare.net/RaginiJain21/data-types-in-python-248466302
Python Library & Module - https://www.slideshare.net/RaginiJain21/python-libraries-and-modules
Basic Python Programs- https://www.slideshare.net/RaginiJain21/basic-python-programs
Python Media Libarary - https://www.slideshare.net/RaginiJain21/python-media-library
Types of Statements in Python Programming LanguageExplore Skilled
The slide describes the types of flow control statements in Python including conditional statement , loop statement , control statement such as break and continue .
The document discusses looping statements in C. It explains that loops allow code to be repeated without having to rewrite the code multiple times. It describes three types of loops: while, do-while, and for. It provides the syntax and an example for each loop type. It also discusses the break and continue statements that can be used within loops to terminate the loop early or skip iterations.
The document discusses different types of conditional and control statements in Python including if, if-else, elif, nested if-else, while, for loops, and else with loops.
It provides the syntax and examples of each statement type. The if statement and if-else statement are used for simple decision making. The elif statement allows for chained conditional execution with more than two possibilities. Nested if-else allows if/elif/else statements within other conditionals. While and for loops are used to repeatedly execute blocks of code, with while looping until a condition is false and for looping over sequences. The else statement with loops executes code when the loop condition is false.
This document discusses C programming concepts including data types, variables, operators, conditional statements, loops, and functions. It contains code examples to find the size of different data types, if/else statements, for/while loops, break/continue statements, and switch statements. The key points covered are:
- Using the sizeof operator to determine the size of int, float, double, char, and other variable types.
- If/else and if/else ladder conditional statements for comparing values.
- For, while, and do-while loop structures for iteration.
- Break and continue statements for early loop termination or skipping iterations.
- Switch statement for multiple conditional comparisons using case labels.
Write a program that removes line numbers in a program listing. Here is a sam...hwbloom150
Write a program that removes line numbers in a program listing. Here is a sample input:
1 print( "Enter a number: " );
2 $number = <>;
3 chomp( $number );
4
5 print "$number is an even number\n” if $number %2==0;
Your program removes all line numbers and preserves the format including empty lines.
Recursion & Erlang, FunctionalConf 14, BangaloreBhasker Kode
The document discusses the history and design of the Erlang programming language. Some key points:
1) Erlang was designed in 1986 at Ericsson for writing concurrent programs that "run forever." It was created by Joe Armstrong to address the needs of building telephony systems.
2) Concurrency was the primary goal in designing Erlang. This influenced decisions like message passing between processes instead of shared memory, and copying data between processes for isolation.
3) Tail recursion and the actor model were incorporated due to their suitability for implementing concurrent processes and distributed systems. Tail recursion allows processes to be spawned efficiently while preserving state.
Traverse surveying involves using instruments to measure distance and direction to create a network of points. There are two main types of traverses - open and closed. Open traverses extend in one direction while closed traverses form a closed loop. Common surveying instruments and methods used in traverse surveying include chain, compass, theodolite, and plane table. Key terms in traverse surveying include bearings, meridians, and reductions of bearings. Traverse calculations involve adjusting angles or directions to ensure closure of the network of points. Sample problems are provided to demonstrate conversions between whole circle bearings, reduced bearings, and fore and back bearings.
This PPT is for First year engineering student,It covered all about C Programming according to Rajastha Technical University Kota.
flowchart, pseudo code, Programming Languages and Language Translators, Identifiers, Constants, Variables, Basic Data Types, Operators, Expressions, type casting, Input / Output Statement, Scope Rules and Storage classes, Preprocessor and Macro Substitution.
This C tutorial covers every topic in C with the programming exercises. This is the most extensive tutorial on C you will get your hands on. I hope you will love the presentation. All the best. Happy learning.
Feedbacks are most welcome. Send your feedbacks to dwivedi.2512@gmail.com. You can download this document in PDF format from the link, http://www.slideshare.net/dwivedi2512/learning-c-an-extensive-guide-to-learn-the-c-language
Programming is hard. Programming correct C and C++ is particularly hard. Indeed, both in C and certainly in C++, it is uncommon to see a screenful containing only well defined and conforming code.Why do professional programmers write code like this? Because most programmers do not have a deep understanding of the language they are using.While they sometimes know that certain things are undefined or unspecified, they often do not know why it is so. In these slides we will study small code snippets in C and C++, and use them to discuss the fundamental building blocks, limitations and underlying design philosophies of these wonderful but dangerous programming languages.
This content has a CC license. Feel free to use it for whatever you want. You may download the original PDF file from: http://www.pvv.org/~oma/DeepC_slides_oct2012.pdf
Algorithms and how to write an algorithmsAhmed Nobi
The document provides information about Ahmed Nobi and Abdelrahman Ashraf, including their contact details, skills, and experience. Ahmed Nobi has over one year of experience as an Android developer and three years of experience as a programming instructor. Abdelrahman Ashraf's skills and brief background are also mentioned. The document then provides an introduction to algorithms, including definitions, how to write an algorithm through obtaining a problem description, analyzing the problem, developing a high-level algorithm, refining with details, and reviewing. Examples of writing algorithms for moving a Jeroo and summing two numbers are included. Decision making with "if" statements and repeating tasks with loops are also covered.
The document discusses exception handling in Ruby programming. It begins with an introduction to exception handling and why it is important. Then it covers the main concepts of exception handling in Ruby, including raise, rescue, ensure, retry and else. It also discusses some caveats and guidelines for exception handling, such as only using exceptions for truly unexpected situations and avoiding exception abuse.
The document provides an introduction to problem solving and programming fundamentals. It defines a computer program as a set of instructions that directs a computer to solve a problem. The document outlines a four-step problem solving process of understanding the problem, devising a plan, carrying out the plan, and looking back. It also discusses analyzing a problem by identifying inputs, outputs, processing, and storage. The design phase involves developing an algorithm to solve the problem. Debugging addresses fixing syntax, runtime, and semantic errors in a program.
The document discusses code smells in PHP code. It defines what a code smell is, which is a surface indication that usually corresponds to a deeper problem in the system. Common code smells discussed include duplicated code, long methods, validation overcrowding, large classes, primitive obsession, nested conditionals, and feature envy. The document provides examples of each smell and discusses approaches for refactoring code to address each smell.
This document discusses the problem solving process in programming. It describes the three main phases: analyzing the problem, designing an algorithm to solve it, and implementing the algorithm in code. In the analysis phase, the problem and requirements are outlined, and a flowchart or pseudocode is used to design the algorithm. In the implementation phase, the algorithm is coded into a program. Finally, the program is tested to verify it works correctly and identify any errors. The key steps of each phase are explained in detail with examples.
This document outlines the goals and agenda for an introduction to programming class using Java. The class will introduce Java programming constructs and problem solving techniques. Students will practice writing, compiling, and debugging simple Java programs. The benefits of using Java as the teaching language are discussed, including its widespread industry use. Good programming practices like writing code incrementally and debugging are emphasized.
SI is supplemental instruction led by Caleb Peacock to help develop study skills. Variables are used to store and reference values in code. There are different data types like integers, floats, and strings. Variables must start with a letter or underscore and can include numbers and underscores but no spaces. Constant variables store fixed values in all caps. Comments describe code and are preceded by #. Basic math operations and mixing data types were demonstrated. The input function prompts users for input values stored in variables.
This document outlines the problem solving process for programming, including three main phases: analyzing the problem, implementing an algorithm to solve it, and maintaining the program. It discusses analyzing the problem by outlining requirements, designing the algorithm using flowcharts and pseudocode, and testing it. The implementation phase includes writing code, debugging for syntax, runtime and logic errors. The maintenance phase modifies the program if requirements change.
This document discusses recursion in programming. It defines recursion as a technique for solving problems by repeatedly applying the same procedure to reduce the problem into smaller sub-problems. The key aspects of recursion covered include recursive functions, how they work by having a base case and recursively calling itself, examples of recursive functions in Python like calculating factorials and binary search, and the differences between recursion and iteration approaches.
Cis 1403 lab1- the process of programmingHamad Odhabi
This lab aims to develop students knowledge and skills needed to create a simple programming code. It covers the process of developing computer programs starting from a simple analysis of the problem, identifying outputs, inputs, and design process/algorithm, convert algorithm to code, testing, and documentation. The student will be introduced to the Java program structure, numerical variable and high-level introduction to data types. The lab does not go into depth explaining the data types and memory storage. These will be discussed in the upcoming labs. Also, the student will be introduced to the REPL cloud environment that will be used to create a simple application.
Here is the first set of notes for the first class in Analysis of Algorithm. I added a dedicatory for my dear Fabi... she has showed me what real idealism is....
The document describes a programmer's experience debugging various issues, including problems caused by optimizations, floating point rounding errors on 486 processors, and "random" crashes caused by garbage collection in Java finalizers deleting corresponding C++ objects. It provides examples of steps taken like adding print statements, using data breakpoints, and switching compilers to get more useful warnings. The lessons emphasized are paying attention to compiler warnings, using compilers with strong warnings, and understanding how different languages and abstractions interact before using them.
Recursion & Erlang, FunctionalConf 14, BangaloreBhasker Kode
The document discusses the history and design of the Erlang programming language. Some key points:
1) Erlang was designed in 1986 at Ericsson for writing concurrent programs that "run forever." It was created by Joe Armstrong to address the needs of building telephony systems.
2) Concurrency was the primary goal in designing Erlang. This influenced decisions like message passing between processes instead of shared memory, and copying data between processes for isolation.
3) Tail recursion and the actor model were incorporated due to their suitability for implementing concurrent processes and distributed systems. Tail recursion allows processes to be spawned efficiently while preserving state.
Traverse surveying involves using instruments to measure distance and direction to create a network of points. There are two main types of traverses - open and closed. Open traverses extend in one direction while closed traverses form a closed loop. Common surveying instruments and methods used in traverse surveying include chain, compass, theodolite, and plane table. Key terms in traverse surveying include bearings, meridians, and reductions of bearings. Traverse calculations involve adjusting angles or directions to ensure closure of the network of points. Sample problems are provided to demonstrate conversions between whole circle bearings, reduced bearings, and fore and back bearings.
This PPT is for First year engineering student,It covered all about C Programming according to Rajastha Technical University Kota.
flowchart, pseudo code, Programming Languages and Language Translators, Identifiers, Constants, Variables, Basic Data Types, Operators, Expressions, type casting, Input / Output Statement, Scope Rules and Storage classes, Preprocessor and Macro Substitution.
This C tutorial covers every topic in C with the programming exercises. This is the most extensive tutorial on C you will get your hands on. I hope you will love the presentation. All the best. Happy learning.
Feedbacks are most welcome. Send your feedbacks to dwivedi.2512@gmail.com. You can download this document in PDF format from the link, http://www.slideshare.net/dwivedi2512/learning-c-an-extensive-guide-to-learn-the-c-language
Programming is hard. Programming correct C and C++ is particularly hard. Indeed, both in C and certainly in C++, it is uncommon to see a screenful containing only well defined and conforming code.Why do professional programmers write code like this? Because most programmers do not have a deep understanding of the language they are using.While they sometimes know that certain things are undefined or unspecified, they often do not know why it is so. In these slides we will study small code snippets in C and C++, and use them to discuss the fundamental building blocks, limitations and underlying design philosophies of these wonderful but dangerous programming languages.
This content has a CC license. Feel free to use it for whatever you want. You may download the original PDF file from: http://www.pvv.org/~oma/DeepC_slides_oct2012.pdf
Algorithms and how to write an algorithmsAhmed Nobi
The document provides information about Ahmed Nobi and Abdelrahman Ashraf, including their contact details, skills, and experience. Ahmed Nobi has over one year of experience as an Android developer and three years of experience as a programming instructor. Abdelrahman Ashraf's skills and brief background are also mentioned. The document then provides an introduction to algorithms, including definitions, how to write an algorithm through obtaining a problem description, analyzing the problem, developing a high-level algorithm, refining with details, and reviewing. Examples of writing algorithms for moving a Jeroo and summing two numbers are included. Decision making with "if" statements and repeating tasks with loops are also covered.
The document discusses exception handling in Ruby programming. It begins with an introduction to exception handling and why it is important. Then it covers the main concepts of exception handling in Ruby, including raise, rescue, ensure, retry and else. It also discusses some caveats and guidelines for exception handling, such as only using exceptions for truly unexpected situations and avoiding exception abuse.
The document provides an introduction to problem solving and programming fundamentals. It defines a computer program as a set of instructions that directs a computer to solve a problem. The document outlines a four-step problem solving process of understanding the problem, devising a plan, carrying out the plan, and looking back. It also discusses analyzing a problem by identifying inputs, outputs, processing, and storage. The design phase involves developing an algorithm to solve the problem. Debugging addresses fixing syntax, runtime, and semantic errors in a program.
The document discusses code smells in PHP code. It defines what a code smell is, which is a surface indication that usually corresponds to a deeper problem in the system. Common code smells discussed include duplicated code, long methods, validation overcrowding, large classes, primitive obsession, nested conditionals, and feature envy. The document provides examples of each smell and discusses approaches for refactoring code to address each smell.
This document discusses the problem solving process in programming. It describes the three main phases: analyzing the problem, designing an algorithm to solve it, and implementing the algorithm in code. In the analysis phase, the problem and requirements are outlined, and a flowchart or pseudocode is used to design the algorithm. In the implementation phase, the algorithm is coded into a program. Finally, the program is tested to verify it works correctly and identify any errors. The key steps of each phase are explained in detail with examples.
This document outlines the goals and agenda for an introduction to programming class using Java. The class will introduce Java programming constructs and problem solving techniques. Students will practice writing, compiling, and debugging simple Java programs. The benefits of using Java as the teaching language are discussed, including its widespread industry use. Good programming practices like writing code incrementally and debugging are emphasized.
SI is supplemental instruction led by Caleb Peacock to help develop study skills. Variables are used to store and reference values in code. There are different data types like integers, floats, and strings. Variables must start with a letter or underscore and can include numbers and underscores but no spaces. Constant variables store fixed values in all caps. Comments describe code and are preceded by #. Basic math operations and mixing data types were demonstrated. The input function prompts users for input values stored in variables.
This document outlines the problem solving process for programming, including three main phases: analyzing the problem, implementing an algorithm to solve it, and maintaining the program. It discusses analyzing the problem by outlining requirements, designing the algorithm using flowcharts and pseudocode, and testing it. The implementation phase includes writing code, debugging for syntax, runtime and logic errors. The maintenance phase modifies the program if requirements change.
This document discusses recursion in programming. It defines recursion as a technique for solving problems by repeatedly applying the same procedure to reduce the problem into smaller sub-problems. The key aspects of recursion covered include recursive functions, how they work by having a base case and recursively calling itself, examples of recursive functions in Python like calculating factorials and binary search, and the differences between recursion and iteration approaches.
Cis 1403 lab1- the process of programmingHamad Odhabi
This lab aims to develop students knowledge and skills needed to create a simple programming code. It covers the process of developing computer programs starting from a simple analysis of the problem, identifying outputs, inputs, and design process/algorithm, convert algorithm to code, testing, and documentation. The student will be introduced to the Java program structure, numerical variable and high-level introduction to data types. The lab does not go into depth explaining the data types and memory storage. These will be discussed in the upcoming labs. Also, the student will be introduced to the REPL cloud environment that will be used to create a simple application.
Here is the first set of notes for the first class in Analysis of Algorithm. I added a dedicatory for my dear Fabi... she has showed me what real idealism is....
The document describes a programmer's experience debugging various issues, including problems caused by optimizations, floating point rounding errors on 486 processors, and "random" crashes caused by garbage collection in Java finalizers deleting corresponding C++ objects. It provides examples of steps taken like adding print statements, using data breakpoints, and switching compilers to get more useful warnings. The lessons emphasized are paying attention to compiler warnings, using compilers with strong warnings, and understanding how different languages and abstractions interact before using them.
Algorithm and flowchart with pseudo codehamza javed
1. Initialize the biggest price to the first price in the list
2. Loop through the remaining 99 prices
3. Compare each price to the biggest and update biggest if greater
4. After the loop, reduce the biggest price by 10%
5. Output the reduced biggest price
This document provides an overview of a course on fundamentals of programming. It introduces the instructor, teaching assistant, and their contact details. It outlines the course credits, grade distribution, textbook, and reference book. It describes the course contents which will cover topics like introduction to programming, variables, operators, conditional statements, loops, functions, arrays, structures, pointers, and file I/O over 18 weeks. It discusses the course outcomes and expectations, attendance, assignment, quiz, and lab policies. Ground rules for student civility are also outlined.
This document summarizes notes from Kent Beck's book "TDD by Example" on test-driven development (TDD). It outlines the core principles of TDD, including writing tests first before code and eliminating duplication. It also describes techniques like red-green-refactor cycles where tests are written to fail initially ("red"), made to pass ("green"), and then code is refactored. The document provides examples of applying TDD to a money conversion problem and discusses patterns for testing, refactoring, and overcoming fears that arise during the process.
This document provides an introduction to C++ programming including problem solving skills, software evolution, procedural and object oriented programming concepts, basic C++ programs, operators, header files, conditional statements, loops, functions, pointers, structures and arrays. It discusses topics such as analyzing problems, planning algorithms, coding solutions, evaluating results, procedural and object oriented paradigms, inheritance, polymorphism, flowcharts, basic syntax examples, and more. Various examples are provided to illustrate key concepts in C++.
Main Java[All of the Base Concepts}.docxadhitya5119
This is part 1 of my Java Learning Journey. This Contains Custom methods, classes, constructors, packages, multithreading , try- catch block, finally block and more.
A workshop hosted by the South African Journal of Science aimed at postgraduate students and early career researchers with little or no experience in writing and publishing journal articles.
Strategies for Effective Upskilling is a presentation by Chinwendu Peace in a Your Skill Boost Masterclass organisation by the Excellence Foundation for South Sudan on 08th and 09th June 2024 from 1 PM to 3 PM on each day.
How to Fix the Import Error in the Odoo 17Celine George
An import error occurs when a program fails to import a module or library, disrupting its execution. In languages like Python, this issue arises when the specified module cannot be found or accessed, hindering the program's functionality. Resolving import errors is crucial for maintaining smooth software operation and uninterrupted development processes.
How to Add Chatter in the odoo 17 ERP ModuleCeline George
In Odoo, the chatter is like a chat tool that helps you work together on records. You can leave notes and track things, making it easier to talk with your team and partners. Inside chatter, all communication history, activity, and changes will be displayed.
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Dr. Vinod Kumar Kanvaria
Exploiting Artificial Intelligence for Empowering Researchers and Faculty,
International FDP on Fundamentals of Research in Social Sciences
at Integral University, Lucknow, 06.06.2024
By Dr. Vinod Kumar Kanvaria
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
This presentation includes basic of PCOS their pathology and treatment and also Ayurveda correlation of PCOS and Ayurvedic line of treatment mentioned in classics.
How to Make a Field Mandatory in Odoo 17Celine George
In Odoo, making a field required can be done through both Python code and XML views. When you set the required attribute to True in Python code, it makes the field required across all views where it's used. Conversely, when you set the required attribute in XML views, it makes the field required only in the context of that particular view.
2. You should know already
• Functions
• Function parameters and arguments
• How to call function
• Global vs local variables
3. Today in the class
1. Recursion:
1. What is it?
2. How to use?
3. Examples
4. Recursion vs iteration
2. Inside my program
3. Debugging
1. what is it?
2. why we need?
3. How to use?
4. Examples.
4. Compiler errors
4. Recursion
• is a method where the solution to a problem
depends on solutions to smaller instances of
the same problem.
example: 2^11 = 2^10 * 2 = 1024 * 2
• one of the central ideas of computer science.
5. How do you empty a vase containing
five flowers?
Answer: if the vase is not empty, you take out one
flower and then you empty a vase containing four
flowers.
How do you empty a vase containing four flowers?
Answer: if the vase is not empty, you take out one
flower and then you empty a vase containing three
flowers.
…
How do you empty a vase containing one flower?
Answer: if the vase is not empty, you take out one
flower and then you empty a vase containing no
flowers.
How do you empty a vase containing no flowers?
Answer: if the vase is not empty, you take out one
flower but the vase is empty so you're done.
6. Base cases vs recursive cases
• one or more base cases:
– input(s) for which the function produces a result
trivially (without recurring),
– Base case for emptyVase: vase with zero flowers
• one or more recursive cases: input(s) for
which the program recurs (calls itself).
Example: vase with flowers bigger than zero.
7. How do you empty a vase containing
five flowers?
• Base: if Flowers=0 done. Vase is empty
• Recursive case: for all flowers>0, take out one
flower, empty Vase of (N-1) flowers
8. emptyVase program code
1. #include <stdio.h>
2. void emptyVase(int numFlowers){
3. if (numFlowers ==0){
4. printf("Vase is empty nown");
5. return;
6. }
7. if (numFlowers>0){
8. numFlowers--;
9. printf("one flower have been taken outn");
10. emptyVase(numFlowers);
11. } //end of IF statement
12. } //end of Function
13. int main () {
14. setvbuf(stdout, NULL, _IONBF, 0);
15. Int flowers =8;
16. emptyVase(flowers);
17. return 0;
18. }
9. Examples of recursive solution
1. Factorial:
Base case:0! = 1
Recursive case: for all n > 0, n! = n(n − 1)!
2. fibbonachi:
Base case:Fn(1) = 1, Fn(2) = 1
Recursive case: for all n > 2, Fn(n) = Fn(n-
1)+Fn(n-2)
3. X^n (x to the power n)
Base case: if n=0, x^n=1
Recursive case: for all n>0, x^n=x*x^(n-1)
11. Factorial recursive function
1. #include <stdio.h>
2. int factorial(int n){
3. //base case
4. if (n==0)
5. return 1;
6. //recursive case
7. if (n>0)
8. return n*factorial(n-1);
9. //default case if n<0
10. return -1;
11. } //end Factorial
12. int main () {
13. setvbuf(stdout, NULL, _IONBF, 0);
14. int number=8;
15. printf("fatorial of %i is %i n", number, factorial(number));
16. return 1;
17. }
12. Factorial iterative function
• #include <stdio.h>
• int factorial(int n){
• int i;
• int res=1;
• for(i=1; i<=n; i++)
• res=res*i;
• return res;
• } //end Factorial
• int main () {
• setvbuf(stdout, NULL, _IONBF, 0);
• int number=8;
• printf("fatorial of %i is %i n", number, factorial(number));
• return 1;
• }
13. Check list recursive function
• Have a base case
• Function call itself (recursive call)
• Recursive call MUST be with different input,
so that the base case must be reached
eventually
14. Recursion vs iteration
• Similarity
– Both repeat block of codes
• Difference
– iteration: loops to repeat the block of code
– recursion: call itself to repeat the block of code
Temination:
iteration: loop condition
recursion: base case
Infinite execution:
iteration: never reach loop condition
recursion: never reach base case
15. Which is better?
• It depends from situation:
– Some problem difficult to solve iteratively
– Some problem difficult to solve recursively
• Math people like recursion
– Shorter solution, abstraction
– To find good recursive solution is not always simple.
• CS people like iteration
– Easier to construct
– Easier to iterate and simulate (less magical)
16. Phillips head vs flat head screwdriver:
which is better?
It depends from situation
iterationrecursion
17. conclusion
• How to know if function recursive?
– It must call itself
• Recursive function must have 2 cases:
– Base case
– Recursive case
• Any recursion can be rewritten with iteration
• Which to choose depends on situation
19. What happens when?
1. you declare new variable?
2. You declare new array
3. You call a function
Computer allocates memory for variable, fro
array
20. function name var name value
continue
line console
main flowers 8 29
emptyVase(8) numFlowers 7 12
one flower have been taken
out
emptyVase(7) numFlowers 6 12
one flower have been taken
out
emptyVase(6) numFlowers 5 12
one flower have been taken
out
emptyVase(5) numFlowers 4 12
one flower have been taken
out
emptyVase(4) numFlowers 3 12
one flower have been taken
out
emptyVase(3) numFlowers 2 12
one flower have been taken
out
emptyVase(2) numFlowers 1 12
one flower have been taken
out
emptyVase(1) numFlowers 0 12
one flower have been taken
out
emptyVase(0) numFlowers 0 vase is empty
23. What is debugging?
Debugging is the process of finding and resolving of
errors in the code that prevent correct operation
of program or computer software.
• To debug a program means:
1. find problem
2. isolate problematic part of code
3. fix it.
24. Finding error with testing
• Testing:
– Give minimum input value
– Give maximum input value
– Give as much as possible diverse input value
Example:
find maximum in the array
time advancer problem
25. Finding errors by debugging
• When Output is incorrect, it is difficult to find an
error.
• What is wrong? How to find an error?
• Debugging:
1. Print debugging
1. Add Printf statements in code, to check internal states of
the program
2. Use debugging tool
1. Eclipse has one
26. Debugging tool
1. Running program Step-by-step
2. Stopping(Pausing) program at some instruction.
And see current program state(breakpoints)
3. Modify program state (modify the values of the
variables) while it is running
27. What is the bug?
• “I’ve debugged a program”
• “Worked the bugs out”
• I fixed the problem, that bugs no longer exist
in my program