Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Write a program to find the sum of odd numbers in first N natural numbers.


Write a function solution that given a three digit integer N and Integer K, returns the maximum possible three digit value that can be obtained by performing at most K increases by 1 of any digit in N

10)adding numbers


Victor has an array of size n.He loves to play with these n numbers.each time he plays with them ,he picks up any two consecutive numbers and adds them. on adding both numbers,it costs him K*(sum of both numbers).


Find the minimum cost of adding all the numbers in the array.


i/p1:size of array


i/p2:elements of array


i/p3:value of K


o/p:return the maximum cost of adding all the numbers of the array.


Ex1:


i/p1:3


i/p2:{1,2,3}


i/p3:2


o/p:18


explanation: There are multiple ways of adding the numbers of an array.


The first way is:1+2=3 cost of adding is 2*3=6.


3+3=6 cost ofadding is 2*6=12


o/p: there are other ways as well,but minimum cost is 18


ex2:


i/p1:4


i/p2:{4,5,6,7}


i/p3:3


o/p:132


explanation:


for minimum cost ,


4+5=9 cost of adding is 3*9=27


6+7=13 cost of adding is 3*13=39


9+13=cost of adding is 3*22=66


Therefore cost is 27+39+66=132



 DigitMon

I used to play Digimon.


Now that I'm a programmer and I have this weird passion of digits, I want to combine them both to create the ultimate program: DigitMon!


This DigitMon program would take an integer input and would output the sum of all the digits of the number. For example, if the input is 243, the output would be 9 because 2 + 4 + 3 = 9. In this case, we say that the DigitMon of 243 is 9.

Instructions:

  1. In the code editor, you are provided with an initial code that asks the user for an integer input and passes this to a function call of the digitMon() function.
  2. The digitMon() function is a recursive function which has the following description:
  3. Return type - int
  4. Name - digitMon
  5. Parameters - one integer
  6. Description - this function is a recursive function that computes the DigitMon of the passed integer.
  7. The digitMon() function is already partially implemented. Your task is to fill in the blanks to make it work.

Input


1. Integer to be processed

Output


Enter·n:·243
DigitMon·of·243·is·9






Reverse Engineering

by CodeChum Admin

Functions that return the value of a base and an exponent is very common so I want to switch it up.


This time, we’re going to try to reverse-engineer these functions and find out the exponent of a certain number based on the value of the result and the base used to get that value.


Instructions:

  1. In the code editor, you are provided with a main() function that asks the user for two integer inputs:
  2. The first integer is the base
  3. The second integer is the result
  4. Furthermore, you are provided with the getExponent() function which is partially implemented. The details of this function are the following:
  5. Return type - int
  6. Name - getExponent
  7. Parameters
  8. int - base
  9. int - result
  10. Description - this recursive function returns the exponent
  11. Your task is to add the base case of this recursive function so that it will work properly.

Input


1. The base

2. The result

Output


Enter·the·base:·2
Enter·the·result:·8
Exponent·=·3




And That's a Fact!

by CodeChum Admin

I love facts. In fact, I dream a lot about facts. Ever since I was a kid, all I ever think of are facts. And that's a fact!


I don't know if that made any sense to you but I think you know about factorials, hmm? In Mathematics, a factorial of a number is the product of all the numbers from 1 up to that number. There is one exception though and that is the factorial of 0 which is 1.


Instructions:

  1. In the code editor, you are provided with a main function that asks the user for an integer input and passes this value to a function called, getFactorial()
  2. The getFactorial() function has the following description:
  3. Return type - int
  4. Name - getFactorial
  5. Parameters - one integer
  6. Description - returns the factorial of the passed integer
  7. Your implementation should be RECURSIVE and you should not use any loops

Input


1. Integer to be processed

Output


Enter·n:·3
Factorial·of·3·is·6




Here We Go Again

by CodeChum Admin

This one’s probably one of the most popular recursion problems in programming. Your task is to create a recursive function that prints out the the first up to the nth number in the Fibonacci sequence by going through the numbers using recursion.


In case you forgot, here is the definition of a Fibonacci sequence:

  • fib(n) = 1 if n = 1 or n = 2
  • fib(n) = fib(n-1) + fib(n-2) when n > 2

Instructions:

  1. In the code editor, you are provided with an initial code with a main() that asks the user for an integer n, which represents the number of elements in the Fibonacci sequence to be printed out.
  2. In addition, you are also provided with an initial displayFibonacci() function which contains the code to supposedly display the first n elements in the Fibonacci sequence. However, it is not working as expected.
  3. Your task is to find where the error is and fix the displayFibonacci() function.

Input


1. Elements to be printed

Output


Enter·n:·4
1·1·2·3

Poorly Executed Mitosis

by CodeChum Admin

A mitosis program has gone out of hand and now does abnormal cell duplication. Rather than scrapping the project, the researchers decided to observe and predict the cell duplication using a program.


Instructions:

  1. In the code editor, you are provided with a main() function that asks the user for the 3 integer inputs required for this program and calls the getResult().
  2. This getResult() function has the following details:
  3. Return type - int
  4. Name - getResult
  5. Parameters
  6. int - Base integer
  7. int - Initial factor
  8. int - Number of times to process
  9. Description - this is a recursive function which implements the desired behavior explained in the problem description
  10. The getResult() function is partially implemented already. Your only task is to add the correct recursive case.

Input


1. Base integer

2. Initial factor

3. Number of times to process

Output


Enter·base·integer:·3
Enter·initial·factor:·2
Enter·number·of·times·to·process:·3
Result·=·54




 I Don't Feel So Good

by CodeChum Admin

In order to preserve Spiderman's last words, Mr. Stark wants us to create a program that takes a string and output the string with each proceeding output having one less character until it outputs only one string.


Instructions:

  1. In the code editor, you are provided with a main() function that asks the user for a string and passes this string and the size of this string to a function call of the function, preserveString().
  2. This preserveString() function has the following description:
  3. Return type - void
  4. Name - preserveString
  5. Parameters
  6. The string
  7. Length of the string
  8. Description - this is a recursive function that prints the string repeatedly. Each time it prints the string, it excludes the last character of the string until only one character is left.
  9. This preserveString() function has already been partially implemented. Your only task is to add the recursive case of this function.

Input


1. String to be processed

Output


Enter·string:·Hello!
Hello!
Hello
Hell
Hel
He
H

Slowly But Surely

by CodeChum Admin

In life, good things take time.


Let's make a simple program that mirrors this beautiful idea where we ask the user for two integer inputs. The first one would represent the starting number and the second one would represent the next n integers after it.


For example, if the first number inputted is 2 and the second number inputted is 3, then the output would be 3, 4, 5 because these are the next 3 integers after 2.


Instructions:

  1. In the code editor, you are provided with a main() function that asks the user for two integers and calls the slowDisplay() function.
  2. This slowDisplay() function is a recursive function which should perform the functionality explained in the problem description above.
  3. This function is only partially implemented as it lacks a base case. Your task is to add the base case needed by this recursive function.

Input


1. Starting integer

2. Number of integers

Output


Enter·starting·integer:·2
Enter·how·many·next·integers:·3
3·4·5
LATEST TUTORIALS
APPROVED BY CLIENTS