INC 161 , CPE 100 Computer Programming

Slides:



Advertisements
Similar presentations
UNIT 12 UNIX I/O Redirection.
Advertisements

1 11/05/07CS150 Introduction to Computer Science 1 Functions Chapter 6, page 303.
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
Declarations/Data Types/Statements. Assignments Due – Homework 1 Reading – Chapter 2 – Lab 1 – due Monday.
1 Introduction to Computers and Programming Class 3 Introduction to C Professor Avi Rosenfeld.
Basic Input/Output and Variables Ethan Cerami New York
1. Function prototype Function prototype is a declaration; indicates the function exists Should have function name, return type and parameter Placed before.
Crypto Project Sample Encrypted Data: –Turing: CS Public\CryptoProjectData Crypto_Short_Keys_P_U.out Crypto_Long_Keys_O_R.out Bonus +10 points on.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
1 C Programming Week 2 Variables, flow control and the Debugger.
Functions with Input/Ouput. Assignments Due – Lab 2 Reading – Chapter 4 –
USER DEFINED FUNCTIONS Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
How to design and code functions Chapter 4 (ctd).
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
Lecture 13: Arrays, Pointers, Code examples B Burlingame 2 Dec 2015.
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman CP 202 Chapter 6.
The Repetition control structure using while loop.
INC 161 , CPE 100 Computer Programming
INC 161 , CPE 100 Computer Programming
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Arrays Declarations CSCI N305
CS1010 Programming Methodology
Functions Dr. Sajib Datta
Iteration statement while do-while
2008/11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park
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.
INC 161 , CPE 100 Computer Programming
CS 1430: Programming in C++.
Visit for more Learning Resources
Buy book Online -
Compiled and ready to run Memory Stack /*
Arrays, Part 1 of 2 Topics Definition of a Data Structure
2008/11/24: Lecture 19 CMSC 104, Section 0101 John Y. Park
2008/11/24: Lecture 19 CMSC 104, Section 0101 John Y. Park
Arrays & pointers C How to Program, 8/e.
INC 161 , CPE 100 Computer Programming
INC 161 , CPE 100 Computer Programming
CSCE 206 Lab Structured Programming in C
Declaration, assignment & accessing
Functions, Part 2 of 3 Topics Functions That Return a Value
INC 161 , CPE 100 Computer Programming
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
INC 161 , CPE 100 Computer Programming
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays .
A function with one argument
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Week 2 Variables, flow control and the Debugger
Computer Programming Techniques Semester 1, 1998
Arrays, Part 1 of 2 Topics Definition of a Data Structure
INC 161 , CPE 100 Computer Programming
Introduction to Problem Solving and Programming
INC 161 , CPE 100 Computer Programming
Functions Extra Examples.
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
CSCE 206 Lab Structured Programming in C
The while Looping Structure
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Course Outcomes of Programming In C (PIC) (17212, C203):
Programming Arrays.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
CSCE 206 Lab Structured Programming in C
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Functions, Part 2 of 3 Topics Functions That Return a Value
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Presentation transcript:

INC 161 , CPE 100 Computer Programming Lab 8

Function is a set of collective commands. Walk to a minimart Walk in Search for a bottle of milk Take out a wallet Take out money Give money to the cashier Walk out of the store Buy milk Function

How to use function BuyMilk() { : } Function Definition Main() Function call

Example 1 #include <stdio.h> addition() { printf(“function\n”); } main() { addition(); printf(“Main\n”);

In/Out Data of a Function Input (arguments) Data Output (return) Note: Functions can have several arguments but only one return.

Example 2 2 inputs 1 output int addition(int a, int b) { int s; s = a + b; return s; } main() { int sum; sum = addition(3, 4); printf(“sum = %d\n”, sum);

Task 1 From the main() given, write a function that calculate the division of two numbers. // Write your function here main() { double result; result = division(3, 4); printf(“division = %lf\n”, result); } You must not change anything in main()

Task 2 From the main() given, write a function that print out the absolute value of a number. // Write your function here main() { int num; printf(“Enter a number: ”); scanf(“%d”,&num); printf(“Absolute = %d\n”,ab(num)); } You must not change anything in main()

Task 3 From the main() given, write a function that find the average of the numbers in an array. // Write your function here main() { float a[6] = {2,8,0,5,1,4}; printf(“Average = %f”,avg(a)); } You must not change anything in main()