💻
C - Structured Programming Language
  • C - Structured Programming Language
  • Structured Programming Language
    • Chapter 0: Overview
      • Overview of Programming
      • Overview of C Programming
      • History of C Programming
      • IDE - Code::Blocks
      • New File Creation and Managing Program Files in Folders
      • C Program Basic Structure
      • Sections of the C Program
      • Steps for Using a Program
      • Flow of a Program Execution
      • First C Program - Hello World
      • Comment
      • Lexical Elements (/Tokens)
      • Keywords
      • Character Set
    • Chapter 1: Data Type, IO
      • Data Type
      • Variable
        • Variable Declaration for Primitive Data Type
        • Variable Address and Input
        • Constant and Macro
        • Variable Scope and Lifetime
        • Variable Storage Type
        • Variable Declaration Vs Definition Vs Initialization
        • Variable Default Value
        • Identifier Naming Rules and Conventions
      • Primitive Data Type: Format Specifier and Size
      • Literals
      • Primitive Data Type: Input Output
        • Input Output Function
        • Integer IO
        • Real Number IO
        • Character IO
        • String IO
        • Formatted Output
        • Formatted Input
        • Return of Scanf and Printf
      • IO Error
      • Escape Sequence / Backslash Characters
      • Data Type Modifiers
        • Data Type Size and Format Specifier
        • Input Output Using Modifiers
      • Data Type Limit
        • Integer Number
        • Floating Point Number
      • Memory Segment
      • Type Casting
      • Declaration of Derived Data Type
        • Array
        • Pointer
        • Function
        • Structure
        • Union
      • Declaration of User Defined Data Type
        • Enumeration
          • Enum Constant Value
          • Enumeration Exercise
        • Typedef
      • Declaration of Other Data Type
        • Boolean
        • Complex and Imaginary Number
        • File
        • Clock and Time
    • Chapter 2: Operator
      • Types of Operators
      • Assignment Operator
      • Arithmetic Operators
        • Math Operation
      • Increment, Decrement Operators
      • Relational Operators
      • Logical Operators
      • Bitwise Operators
      • Miscellaneous Operators
      • Operator Precedence and Associativity
      • Programming Syntax & Expression
      • Operator Exercise
    • Chapter 3: Conditional Statement
      • Truth Value
      • If Else Exercise
        • Zero, Positive, Negative - Number Sign Test
        • Voting Eligibility
        • Complex Numbers Equality
        • Different Example
          • Print a Digit into Word
          • Grade Evaluation
          • FizzBuzz
          • EVEN or ODD
          • Leap Year
          • Maximum of 2 Numbers
          • Maximum of 3 Numbers
          • Minimum of 2 Numbers
          • Minimum of 3 Numbers
      • Ternary Operator
        • Ternary Operator Exercise
      • Switch Statement
        • Switch Statement Exercise
    • Chapter 4: Loop
      • Loop Basic
      • Series Printing using Loop
      • Summation and Factorial
      • Loop Exercise
      • Number Theory
      • Break and Continue
      • Nested Loop
      • Managing Test Case
      • Goto Statement
    • Chapter 5: Pointer and Dynamic Memory Allocation
      • Pointer Fundamental Concept
        • Pointer Declaration
        • Types of Pointer
        • Pointer for Primitive Data Types
        • Pointer Referencing, Initialization, Accessing, Dereferencing
        • Pointer Size
      • Pointer Operation
        • Value Assignment/Update
        • Pointer Input Output
        • Pointer and Operator
          • Assignment Operator
          • Arithmetic Operator
          • Increment/Decrement Operator
          • Relational Operator
        • Pointer and Flow Control
      • Multilevel Pointer
      • Dynamic Memory Allocation (DMA)
        • Dynamic Memory Allocation (DMA)
        • DMA for Primitive Data Types
        • Pointer Operation after DMA
    • Chapter 6: Function & Recursion
      • Type of Function
      • Function Exercise
      • Conditional Statement and Function
      • Loop Exercise using Function
      • Pointer and Function
      • Recursion
        • Example
        • Pointer
    • Chapter 7: Array
      • Array Fundamental Concept
        • Necessity
        • Declaration (1D Array)
        • Initialization
        • Access
        • Assignment
        • Address
        • User Input
          • Test Case
      • Function and Array
      • Basic Array Operation
        • Statistical Operations
          • Summation
          • Average (Mean), Median
          • Frequency Table, Mode
          • Standard Deviation, Variance
          • Covariance, Correlation
        • Searching
          • Linear Search
          • Binary Search
          • Maximum
          • Minimum
        • Update
          • Index Based
          • Element Based
        • Delete
          • Index Based
          • Element Based
        • Insert
          • Index Based
          • Element Based
        • Sorting
          • Selection Sort
          • Insertion Sort
          • Bubble Sort
      • Other Array Operation
        • Copy
        • Reverse
        • Compare
        • Merge
        • Split
        • Cyclic Permutation
      • Pointer and Array
        • Basic
        • Insert
        • Delete
        • Summation
        • Reverse
        • Compare
        • Merge
        • Split
        • Cyclic Permutation
      • Pointer and Array
      • DMA and Array
      • 2D Array
    • Chapter 8: Character and String
      • Character
        • Declaration and Initialization
        • ASCII Code
        • Input Output
        • Conditional Statement
        • Character Arithmetic
      • String
        • String Declaration and Initialization
        • Input Output
        • Character Count in String
        • Character Conversion in String
        • String Operations
          • Substring
      • String and Pointer
    • Chapter 9: Structure
      • Basic of Structure
      • Structure Pointer
      • Function and Structure
      • Nested Structure
      • DMA and Structure
    • Chapter 10: File
    • Miscellaneous
      • Working with Math Functions
      • Working with Time Functions
      • Union
      • Preprocessor
      • Custom Header File
      • Error Handling
      • Graphics
      • Other
      • Coding Convention
      • Identifiers (Variable, Function & Structure) Naming Convention
      • Sizeof
      • Exit, Abort
      • Assert
    • Reference
      • Online Learning Material
  • Exercise
    • Problem Set 0: IDE, First C Program - 4
    • Problem Set 1: Data Types, IO - 55
      • Data Type, Variable, Format Specifier, Input, Output, String - 33
      • Data Type, Input, Output - 8
      • Data Type, Data Type Modifier, Format Specifier, Size, Limit, Address - 9
      • Formatted Input-Output - 4
    • Problem Set 2: Operator - 108
      • 2.1 Assignment Operator - 11
      • 2.2 Arithmetic Operator - 73
        • 2.2.1 Arithmetic Operator [5]
        • 2.2.2 Arithmetic Operator Exercise [10]
        • 2.2.3 Scale Conversion [25]
        • 2.2.4 Geometrical Shapes [35]
      • Bitwise Operator - 11
      • Use of Library Functions - 23
    • Problem Set 3: Conditional Statements - 47
    • Problem Set 4: Loop - 124
      • Sequence and Series - 33
      • More Loop Exercise - 52
      • Test Case - 7
      • Loop Nested - 32
    • Problem Set 5: Pointer and Dynamic Memory Allocation
      • Pointer Exercise
    • Problem Set 6: Function and Recursion - 42
      • Recursion
    • Problem Set 7: Array
      • One Dimensional Array - 114
      • Two Dimensional Array
    • Problem Set 8: Character and String - 61
      • Character - 29
      • String - 32
    • Problem Set 9: Structure
    • Problem Set 10: File
  • Solution
    • 0: IDE, First C Program
    • 1: Data Types, IO
    • 2: Operator
      • 2.1 Assignment Operator
      • 2.2 Arithmetic Operator
    • 3: Conditional Statements
      • 3.1 Conditional Statement
      • 3.2 Relational Operator
      • 3.3 Logical Operator
      • 3.4 Max, Min Median, Sorting
      • 3.5 Divisibility
    • 4: Loop
      • 4.1.1 Loop (Repetition)
      • 4.1.2 Print Sequence
      • 4.1.3 Summation of Series
      • 4.2 Loop Exercise
    • 5: Pointer and Dynamic Memory Allocation
    • 6: Function and Recursion
      • 5.1 Types of User Defined Function
      • 5.2 Exercise - Function
    • 7: Array
    • 8: Character and String
      • 7.1 Character Basic
      • 7.2 Character Input
      • 7.3 ASCII Code
      • 7.4 Character Test
      • 7.5 Character Conversion
      • 7.6 Character Arithmetic Operation
    • 9: Structure
    • 10: File
Powered by GitBook
On this page
  • Write the Function for each problem. Print each line trailing with a new line.
  • Problem Set 6.1: Passing Arguments and Returning Values
  • Problem Set 6.2: Arithmetic Operation
  • Problem Set 6.3: Conditional Statement
  • Problem Set 6.4: Loop
  1. Exercise

Problem Set 6: Function and Recursion - 42

Write the Function for each problem. Print each line trailing with a new line.

Problem Set 6.1: Passing Arguments and Returning Values

  1. Print "Hello World"

    • Function Prototype: void print_hello(void)

    • Argument: No Argument

    • Process: Print the String Constant "Hello World"

    • Return: No Return

  2. Print an Integer Number

    • Function Prototype: void print_int(int)

    • Argument: One Integer Constant/Variable as Value

    • Process: Print the Integer Number

    • Return: No Return

  3. Print a Float Number

    • Function Prototype: void print_float(float)

    • Argument: One Float Constant/Variable as Value

    • Process: Print the Float Number

    • Return: No Return

  4. Print a Double Number

    • Function Prototype: void print_double(double)

    • Argument: One Double Constant/Variable as Value

    • Process: Print the Double Number

    • Return: No Return

  5. Print a Character

    • Function Prototype: void print_char(char)

    • Argument: One Character Constant/Variable as Value

    • Process: Print the Character

    • Return: No Return

  6. Input an Integer Number and return the number

    • Function Prototype: int input_int()

    • Argument: No Argument

    • Process: Take an Integer Number input from the user

    • Return: Return the Integer Input

  7. Input a Float Number and return the number

    • Function Prototype: float input_float()

    • Argument: No Argument

    • Process: Take a Float Number input from the user

    • Return: Return the Float Input

  8. Input a Double Number and return the number

    • Function Prototype: double input_double()

    • Argument: No Argument

    • Process: Take a Double Number input from the user

    • Return: Return the Double Input

  9. Input a Character and return the Character

    • Function Prototype: char input_char()

    • Argument: No Argument

    • Process: Take Character input from the user

    • Return: Return the Character Input

  10. Input a String and return the String

    • Function Prototype: char* input_string()

    • Argument: No Argument

    • Process: Take a String input from the user

    • Return: Return the String Input

    • NB: String is a Character Array in C Programming, Return the Array Pointer

  11. Print a String

    • Function Prototype: void print_string(char*)

    • Argument: One String Argument (Pass Your Name as String) as value

    • Process: Print Hello “Your Name"

    • Return: No Return

    • NB: String is a Character Array in C Programming, Pass a String inside the double quotation ("String Inside")

Problem Set 6.2: Arithmetic Operation

  1. Calculate Square

    • Function Prototype:

      • int square(int)

      • float square(float)

      • double square(double)

    • Argument: One Integer/Float/Double Constant/Variable as Value

    • Process: Calculate the Square of the given Integer/Float/Double Number

    • Return: Return the Squared Number

  2. Calculate Cube

    • Function Prototype:

      • int cube(int)

      • float cube(float)

      • double cube(double)

    • Argument: One Integer/Float/Double Constant/Variable as Value

    • Process: Calculate the Cube of the given Integer/Float/Double Number

    • Return: Return the Cubed Number

  3. Calculate Power (X^Y)

    • Function Prototype: power(base, exponent) [Consider the First Argument as Base and Second Argument as Exponent]

      • int power(int, int)

      • float power(float, int), float power(float, float)

      • double power(double, int), double power(double, double)

    • Argument: One Integer/Float/Double Constant/Variable as Base and Another Integer/Float/Double Constant/Variable as Exponent

    • Process: Calculate the Power of the given Integer/Float/Double Numbers as Base^Exponent

    • Return: Return the Resulting Number

  4. Calculate Summation

    • Function Prototype: int summation(int, int)

    • Argument: Two integer numbers

    • Process: Calculate the summation of the given numbers

    • Return: Return the summation of the given numbers

  5. Calculate Difference

    • Function Prototype: int difference(int, int)

    • Argument: Two integer numbers

    • Process: Calculate the difference between the given numbers

    • Return: Return the difference between the given numbers

  6. Calculate Product

    • Function Prototype: int product(int, int)

    • Argument: Two integer numbers

    • Process: Calculate the product of the given numbers

    • Return: Return the product of the given numbers

  7. Calculate Quotient

    • Function Prototype: int quotient(int, int)

    • Argument: Two integer numbers

    • Process: Calculate the quotient of the given numbers

    • Return: Return the quotient of the given numbers

  8. Calculate Reminder

    • Function Prototype: int reminder(int, int)

    • Argument: Two integer numbers

    • Process: Calculate the remainder of the given numbers

    • Return: Return the remainder of the given numbers

  9. Calculate Average

    • Function Prototype: float average(int, int, int)

    • Argument: Three integer numbers

    • Process: Calculate the average of the given numbers

    • Return: Return the average of the given numbers

  10. Find the Area of a Triangle using the Base and Height

    • Function Prototype: float triangle_area(float, float)

    • Argument: Two float numbers as base and height

    • Process: Calculate the area of the triangle using base and height

    • Return: Return the area of the triangle

  11. Find the Area of a Triangle using the length of 3 sides

    • Function Prototype: float triangle_area(float, float, float)

    • Argument: Three float numbers as the length of 3 sides

    • Process: Calculate the area of the triangle using the length of 3 sides

    • Return: Return the area of the triangle

  12. Find the Area of a Rectangle using the length of 3 sides

    • Function Prototype: float rectangle_area(float, float)

    • Argument: Two float numbers as the length of 2 sides

    • Process: Calculate the area of the rectangle using the length of 3 sides

    • Return: Return the area of the rectangle

  13. Find the Area of a Circle using the Radius

    • Function Prototype: float circle_area(float)

    • Argument: One float number as the radius

    • Process: Calculate the area of the circle using the radius

    • Return: Return the area of the circle

  14. Convert the Temperature from Celsius Scale to Fahrenheit Scale

    • Function Prototype: float to_fahrenheit(float)

    • Argument: One float number as the temperature in the Celsius scale

    • Process: Calculate the temperature in Fahrenheit Scale

    • Return: Return the temperature to Fahrenheit Scale

  15. Convert the Temperature from Fahrenheit Scale to Celsius Scale

    • Function Prototype: float to_celsius(float)

    • Argument: One float number as the temperature in the Fahrenheit scale

    • Process: Calculate the temperature in Celsius Scale

    • Return: Return the temperature to the Celsius Scale

Problem Set 6.3: Conditional Statement

  1. Determine EVEN or ODD

    • Function Prototype:

      • void test_even_odd(int)

    • Argument: One Integer Variable as Value

    • Process: If the given number is even then print Even, otherwise print Odd

    • Return: No Return

  2. Determine EVEN or ODD

    • Function Prototype:

      • int is_even(int)

      • _Bool is_even(int)

      • bool is_even(int)

    • Argument: One Integer Variable as Value

    • Process: If the given number is even then return true, otherwise return false

    • Return: Return true or false based on the condition

  3. Determine Leap Year or Not

    • Function Prototype:

      • int is_leap_year(int)

      • _Bool is_leap_year(int)

      • bool is_leap_year(int)

    • Argument: One Integer Variable as Value

    • Process: If the given number is Leap Year then return true, otherwise return false

    • Return: Return true or false based on the condition

  4. Find the Maximum between 2 numbers

    • Function Prototype:

      • int maximum(int, int)

      • float maximum(float, float)

      • double maximum(double, double)

      • char maximum(char, char)

    • Argument: Two Integer/float/double/character Variables as Value

    • Process: If the first number is larger then return it, otherwise return the other number

    • Return: Return the maximum between two numbers

  5. Find the Minimum between 2 numbers

    • Function Prototype:

      • int minimum(int, int)

      • float minimum(float, float)

      • double minimum(double, double)

      • char minimum(char, char)

    • Argument: Two Integer/float/double/character Variables as Value

    • Process: If the first number is smaller then return it, otherwise return the other number

    • Return: Return the minimum between two numbers

  6. Find the Maximum between three (3) numbers

    • Function Prototype:

      • int maximum(int, int, int)

      • float maximum(float, float, float)

      • double maximum(double, double, double)

      • char maximum(char, char, char)

    • Argument: Three Integer/float/double/character Variables as Value

    • Process: If the first number is the largest then return it, if the second number is the largest then return it, otherwise return the third number

    • Return: Return the maximum among three numbers

  7. Find the Minimum between three (3) numbers

    • Function Prototype:

      • int minimum(int, int, int)

      • float minimum(float, float, float)

      • double minimum(double, double, double)

      • char minimum(char, char, char)

    • Argument: Three Integer/float/double/character Variables as Value

    • Process: If the first number is the smallest then return it, if the second number is the smallest then return it, otherwise return the third number

    • Return: Return the minimum among three numbers

Problem Set 6.4: Loop

  1. Calculate the summation of natural numbers up to N.

  2. Calculate the summation of odd natural numbers up to N.

  3. Calculate the summation of even natural numbers up to N.

  4. Calculate the summation of the square of odd natural numbers up to N.

  5. Calculate the summation of the cube of even natural numbers up to N.

  6. Calculate factorial N.

  7. Print each divisor (or factor) of the given number.

  8. Calculate the total number of divisors of a number.

  9. Calculate the summation of divisors of a number.

PreviousPointer ExerciseNextRecursion

Last updated 9 months ago