Repetition and Iteration, Part II - PowerPoint PPT Presentation

About This Presentation
Title:

Repetition and Iteration, Part II

Description:

Repetition and Iteration, Part II. ANSI-C. For ... int fact(int number){ int result ... for (value = 2; value = number; value = value 1) result = result ... – PowerPoint PPT presentation

Number of Views:11
Avg rating:3.0/5.0
Slides: 7
Provided by: defau1007
Learn more at: https://www.cs.uno.edu
Category:

less

Transcript and Presenter's Notes

Title: Repetition and Iteration, Part II


1
Repetition and Iteration, Part II
  • ANSI-C

2
For loop
  • Syntax
  • for (initialization condition increment)
    statement
  • This is equivalent to
  • initialization
  • while (condition) statement incremen
    t

3
For loop example
  • int fact(int number)
  • int result 1
  • int count
  • for (count 2 count lt number count count
    1)
  • result result count
  • return result

4
For loop example
  • int squareAddition( int number )
  • int result 1
  • int value
  • for (value 2 value lt number value value
    1)
  • result result value value
  • return result

5
For loop example
  • int naturalLog( int number )
  • int result 0
  • int value
  • for (value 1 value 2 lt number value
    value 2)
  • result result 1
  • return result

6
For loop example another version of naturalLog
  • int naturalLog( int number )
  • int result
  • int value
  • for (result 0, value 1 (value value 2)lt
    number )
  • result result 1
  • return result
Write a Comment
User Comments (0)
About PowerShow.com