Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCE 206 Lab Structured Programming in C

Similar presentations


Presentation on theme: "CSCE 206 Lab Structured Programming in C"— Presentation transcript:

1 CSCE 206 Lab Structured Programming in C
SPRING 2019 Lecture 5

2 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.

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

4 Function Calling

5 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.

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

7 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.

8 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.

9 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.


Download ppt "CSCE 206 Lab Structured Programming in C"

Similar presentations


Ads by Google