ECE
ECE 1574 Week 9 Function Anatomy.docx

# ECE 1574 Week 9 Function Anatomy.docx - ECE1574 Problem...

• Notes
• 1

This preview shows page 1. Sign up to view the full content.

ECE1574 – Problem Solving for Engineers With C++ Page 1 of 1 Week 9 – Notes (2) Anatomy of a Function Let’s create a function to calculate the factorial of a number. We will call the function fact() . It will return an integer value. (Factorial = n! = n*(n-1)*(n-2)* . . . * 1, or the multiplication of all integers from 1 to n.) The example includes the function prototype at the top with the preprocessor directives, a function call within the main() function, and a function definition which follows the main() function. int fact(int); // function prototype for fact – it lists argument types in () // there is only one argument, an integer #include <iostream> using namespace std; int main() { int b; cin >> b; if(b>=0) cout<<b<<"! is " << fact(b) <<endl; // function call with argument b else cout <<"not defined for negative numbers"
This is the end of the preview. Sign up to access the rest of the document.
• Spring '08
• Negative and non-negative numbers, #include, nfact

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern