1.3 Write a function to output an arbitrary double number (which
might be negative using only printDigit for VO
Write a recursive function that returns the number of 1 in the
binary representation 1 in the representation of N/2 plus 1, if N
is odd
Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
Brother since printDigit is not given so I am returning output of function to main. In case any change please comment.
#include <iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
double func()
{
double num=(double)rand()/(double)RAND_MAX;
return num*10.0-5.0;
}
int main()
{
srand(time(NULL));
cout<<func();
return 0;
}
2)
#include <iostream>
#include<cstdlib>
using namespace std;
int func(int n)
{
if(n==0)
return 0;
else
{
if(n%2==0)
return func(n/2);
else
return func(n/2)+1;
}
}
int main()
{
cout<<func(63);
return 0;
}
Kindly revert for any queries
Thanks.
1.3 Write a function to output an arbitrary double number (which might be negative using only...
Write a recursive method in **pseudocode** that returns the number of 1’s in the binary representation of N. Use the fact that this equal to the number of 1’s in the representation of N/2, plus 1, if N is odd java pseudocode is best
Write a function: that, given two non-negative integers A and B, returns the number of bits set to 1 in the binary representation of the number A * B. For example, given A = 3 and B = 7 the function should return 3, because the binary representation of A * B = 3 * 7 = 21 is 10101 and it contains three bits set to 1. Assume that: In your solution, focus on correctness. The performance of your...
Write the function deep_contains. It takes as input a number and a list. That list might contain lists as elements, and those lists might contain lists, etc. The deep_contains' function should return a Boolean indicating whether the number is contained inputted list, or a sublist of it, or a sublist of that, and so forth. For example: deep_contains (3, (1,3,5]) returns True deep_contains(3, 11, [3,5]]) returns True deep_contains (3, 1, [[3,4],5),6]) returns True deep_contains (2, (1,3,5]) returns False This function...
Using Python In the decimal system (base 10), a natural number is represented as a sequence dndn?1 . . . d0 of (decimal) digits, each of which is in the range 0..9. The value of the number is d0 ×100 +d1 ×101 +···+ dn ×10n. Similarly, in the binary system (base 2), a natural number is represented as a sequence bnbn?1 · · · b0 of (binary) digits, each of which is 0 or 1. The value of the number...
In Java Write a program that reads an arbitrary number of 25 integers that are positive and even. The program will ask the user to re-enter an integer if the user inputs a number that is odd or negative or zero. The inputted integers must then be stored in a two dimensional array of size 5 x 5. Please create 3 methods: 1. Write a method public static int sum2DArray( int [1] inputArray ) The method sums up all elements...
Write a C++ program that asks the user to enter a single number from 1 to 50 and a choice of "even" or "odd". Using a recursive function, output the sum of all the even or odd integers from 1 up to (and including) that number. Your program does not need to loop and accept more input (only one input of the number then even/odd).
This is python coding recursive function question. Could anyone help me figuring out these not using built-in function? Thanks. Write a recursive function factorial(n) that returns the value of n!=1⋅2⋅3⋅⋯⋅n. 2. Write a recursive function reverse(text) that returns the reverse of the string named text. 3. Write a recursive function countUpper(s) that returns the number of uppercase letters in the string s. 4. Write a recursive function equal(list1, list2) that returns a Boolean value indicating whether the two lists are...
In Java* Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...
Using java programming. Question 1. Write a recursive function fibo(n) that returns the nth Fibonacci number which is defined as follows: fibo(0) = 0 fibo(1) = 1 fibo(n) = fibo(n-1) + fibo(n-2) for n >= 2 Question 2. Write a recursive function that calculates the sum of quintics: 1power of5 + 2power of5 + 3power of5 + … + n5 Question 3. Write a program to find a route from one given position to another given position for the knight...
Write a C program, that would take a negative number as a input from the console, and convert it into 2’s complement binary representation. Recall that, there are two steps to that: ● 1’s complement of the positive bitwise representation, which is similar to bit flipping. ○ Find out the appropriate bitwise operator for that, or do it manually. ● Add 1 with the 1’s complement number. ○ Simply add 1 with the number you get in the previous step....