CSCE 206 Lab Structured Programming in C

Slides:



Advertisements
Similar presentations
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Advertisements

Discovering Divisibility Rules.
Start. More Loops 03/14/11 Look at geometric series example.
ITC 240: Web Application Programming
1 Gentle Introduction to Programming Session 2: Functions.
11.3 Function Prototypes A Function Prototype contains the function’s return type, name and parameter list Writing the function prototype is “declaring”
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
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.
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.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
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.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
Chapter 9: MuPAD Programming II Procedures MATLAB for Scientist and Engineers Using Symbolic Toolbox.
Textbook Problem Java – An Introduction to Problem Solving & Programming, Walter Savitch, pp.219, Problem 08.
DIVISIBILITY RULES.
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.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Who Will Be the Champion? Place Value Jeopardy DivisibilityMultiplying Three Digit by a One Digit Multiplying Two Digit by a One Digit Multiplication and.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
Count and add list of numbers From user input and from file.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Factor A factor of an integer is any integer that divides the given integer with no remainder.
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.
All even numbers are divisible by 2 Even numbers are numbers that end with either 0, 2, 4, 6, or 8.
1 CSC103: Introduction to Computer and Programming Lecture No 16.
CSC1201: Programming Language 2 1 Functions. 2 Function declaration: return_type FuncName( Type arg1, Type arg2,….. Type argN) { function body } A program.
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.
C allows programmer to define their own function according to their requirement. These types of functions are known as user-defined functions. Suppose,
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.
1 BUILDING JAVA PROGRAMS CHAPTER 5 PROGRAM LOGIC AND INDEFINITE LOOPS.
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.
The Repetition control structure using while loop.
Chapter 7: Function.
Chapter 6: Loops.
CS1010 Discussion Group 11 Week 6 – One dimensional arrays.
Exercise 24 ÷ 2 12.
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
2.6 Factoring Simple Quadratics
Subroutines in Computer Programming
Functions.
While Loops in Python.
Ch. 8 – Sequences, Series, and Probability
Functions in C.
CSC1201: Programming Language 2
While Loop Design ENGI 1020 Fall 2018.
CSCE 206 Lab Structured Programming in C
Intro to Nested Looping
Dr. Joe Anderson September 6, 2017
CSCE 206 Lab Structured Programming in C
Divisibility Rules.
Intro to Nested Looping
Suppose I want to add all the even integers from 1 to 100 (inclusive)
Programming Languages
CSC1201: Programming Language 2
Java
Review of Integers and Solving Equations
6.2 Factoring Simple Quadratics
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
REPETITION Why Repetition?
Presentation transcript:

CSCE 206 Lab Structured Programming in C SPRING 2019 Lecture 5

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 from math.h, not user-defined.

Function Syntax returnType functionName(type1 argument1, { // Body of the function }

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. Use function for the summation of series.

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

Practice Problem-3 Write a program that takes an integer n from the input and, If n is negative: make it positive, add 5 and print it. If n is divisible by 2: print the next 10 numbers. If n is divisible by 3: print the number of digits of n. Hint: you will need a loop. Use one function for each if case.

Practice Problem-4 Write a program that takes an integer n from the input and print if the number is a palindrome. Use one function.

Practice Problem-5 Write a program that takes an integer n from the input and print if the number is a palindrome. Use one function. Use recursion.