CSCE 206 Lab Structured Programming in C

Slides:



Advertisements
Similar presentations
Introduction to Programming Java Lab 7: Loops 22 February JavaLab7 lecture slides.ppt Ping Brennan
Advertisements

Procedures and Functions. What are they? They are both blocks of code that can be reused to perform specific task. However there is a difference: Function-
What is the sum of the following infinite series 1+x+x2+x3+…xn… where 0
Lecture 03 – Sequences of data.  At the end of this lecture, students should be able to:  Define and use functions  Import functions from modules 
Start. More Loops 03/14/11 Look at geometric series example.
ITC 240: Web Application Programming
1 Gentle Introduction to Programming Session 2: Functions.
1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
1 CS 105 Lecture 10 Functions Version of Mon, Mar 28, 2011, 3:13 pm.
1.9 Methods academy.zariba.com 1. Lecture Content 1.What is a method? Why use methods? 2.Void Methods and methods with parameters 3.Methods which return.
Arrays (Part II). Two- and Multidimensional Arrays Two-dimensional array: collection of a fixed number of components (of the same type) arranged in two.
Special Sum The First N Integers. 9/9/2013 Sum of 1st N Integers 2 Sum of the First n Natural Numbers Consider Summation Notation ∑ k=1 n k =
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
Functions.
Loop Exercise 1 Suppose that you want to take out a loan for $10,000, with 18% APR, and you're willing to make payments of $1,200/month. How long will.
JavaScript Lecture 6 Rachel A Ober
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
12.1 Sequences and Series ©2001 by R. Villar All Rights Reserved.
Textbook Problem Java – An Introduction to Problem Solving & Programming, Walter Savitch, pp.219, Problem 08.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Functions CS 103 March 3, Review A function is a set of code we can execute on command to perform a specific task A function is a set of code we.
A step-by-step procedure for solving a problem in a finite number of steps.
CSE 501N Fall ‘09 12: Recursion and Recursive Algorithms 8 October 2009 Nick Leidenfrost.
Function Problems. Write Functions Asks users whether the user wants to continue of not, then returns the answer. Takes two integers and returns 1 if.
Count and add list of numbers From user input and from file.
Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular.
Week 61 Introduction to Programming Ms. Knudtzon C Period Tuesday October 12.
Exercise 3 Example> Write a C function that implements /* input : integer value n output : */ int f ( int n ) { int i, sum=0; for (i=1;i
Lecture 7: Menus and getting input. switch Multiple-selection Statement switch Useful when a variable or expression is tested for all the values it can.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
Sum of Arithmetic Sequences. Definitions Sequence Series.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
C allows programmer to define their own function according to their requirement. These types of functions are known as user-defined functions. Suppose,
CS1010: Programming Methodology
L AB 4 July 5th. F OR LOOP Exercise 1: Find two ways of “Summing all 1, 2, and 3 digit prime numbers.” Use for loop Hint: isprime, primes.
Introduction to Programming Python Lab 7: if Statement 19 February PythonLab7 lecture slides.ppt Ping Brennan
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
8.1 – Sequences and Series. Sequences Infinite sequence = a function whose domain is the set of positive integers a 1, a 2, …, a n are the terms of the.
Chapter 9: Value-Returning Functions
Chapter 7: Function.
INC 161 , CPE 100 Computer Programming
Chapter 6: Loops.
Topic:- ALGORITHM Incharge Faculty – Lokesh Sir.
Functions.
While Loops in Python.
Ch. 8 – Sequences, Series, and Probability
While Loop Design ENGI 1020 Fall 2018.
CSCE 206 Lab Structured Programming in C
CSCE 206 Lab Structured Programming in C
Intro to Nested Looping
Dr. Joe Anderson September 6, 2017
Warm Up Use <, > or = to complete each statement:
Visual Basic – Decision Statements
If Statements.
Intro to Nested Looping
Suppose I want to add all the even integers from 1 to 100 (inclusive)
CSCE 206 Lab Structured Programming in C
Programming Concepts and Database
Loops and Simple Functions
Java
CSCE 206 Lab Structured Programming in C
To factor a whole number as a product of prime numbers
CSCE 206 Lab Structured Programming in C
CSCE 206 Lab Structured Programming in C
CSCE 206 Lab Structured Programming in C
Multiplication and Division of Integers
Hossain Shahriar CISC 101: Fall 2011 Hossain Shahriar
REPETITION Why Repetition?
Presentation transcript:

CSCE 206 Lab Structured Programming in C Fall 2018 Lecture 5 Ehsanul Haque Nirjhar

Function Block of code to perform a specific task A large problem can be solved using different functions User defined functions can take different parameters and return a result, which can be used in the main function Example: pow(base, exponent)takes 2 parameters as input and returns a result. It is a built-in function; not user- defined.

Function Syntax

Function Calling

Function Calling

Practice Problem-1 Write a program that reads in an integer value for n and then sums the integers from n to 2*n if n is nonnegative, or from 2 * n to n if n is negative. Hint: Use function for the summation of series.

Practice Problem-2 Write a program that prints all the prime numbers from 2 to 1000. Hint: Use function to check whether a number is prime or not.