Complete the given program code by creating the sumOfOdd function so that when program executes it will display the sum of the numbers of Odd or Even from 1 to the input value. B fun main() { print("Enter a number: ") val a = rdInt () print("Display the sum of odd numbers [Y/N]: ") val choice rd() var isOdd false if (choice.equals("Y")) isOdd = true sumofodd (isodd, a) //create this function } private fun rd() = readLine()!! private fun rdInt() = rd().toInt () Example Output 1 Enter a number: 7 Display the sum of odd numbers [Y/N]: Y The sum of odd numbers from 1 to 7 is 16 Example Output 2 Enter a number: 7 Display the sum of odd numbers [Y/N]: N The sum of even numbers from 1 to 7 is 12
Complete the given program code by creating the sumOfOdd function so that when program executes it will display the sum of the numbers of Odd or Even from 1 to the input value. B fun main() { print("Enter a number: ") val a = rdInt () print("Display the sum of odd numbers [Y/N]: ") val choice rd() var isOdd false if (choice.equals("Y")) isOdd = true sumofodd (isodd, a) //create this function } private fun rd() = readLine()!! private fun rdInt() = rd().toInt () Example Output 1 Enter a number: 7 Display the sum of odd numbers [Y/N]: Y The sum of odd numbers from 1 to 7 is 16 Example Output 2 Enter a number: 7 Display the sum of odd numbers [Y/N]: N The sum of even numbers from 1 to 7 is 12
C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.2: Returning A Single Value
Problem 12E
Related questions
Question
100%
Use Kotlin
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 2 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning