Answer:
The function in Python is as follows:
def d2x(d, x):
if d > 1 and x>1 and x<=9:
output = ""
while (d > 0):
output+= str(d % x)
d = int(d / x)
output = output[::-1]
return output
else:
return "Number/Base is out of range"
Explanation:
This defines the function
def d2x(d, x):
This checks if base and range are within range i.e. d must be positive and x between 2 and 9 (inclusive)
if d >= 1 and x>1 and x<=9:
This initializes the output string
output = ""
This loop is repeated until d is 0
while (d > 0):
This gets the remainder of d/x and saves the result in output
output+= str(d % x)
This gets the quotient of d/x
d = int(d / x) ----- The loop ends here
This reverses the output string
output = output[::-1]
This returns the output string
return output
The else statement if d or x is out of range
<em> else:</em>
<em> return "Number/Base is out of range"</em>
<em />
Answer:
Following are the program in the C++ Programming Language:
#include <iostream>//header file
using namespace std;//namespane
//set main method
int main() {
int a[100]; //set integer type array variable
int value, i = 0; //set integer variables
cout<<"Enter less than 0 to exit:"<<endl; //message for exit
cout<<"Enter the integer numbers:"<<endl; //message to enter numbers
do{ //set do while
cin>>value; //get input from the user
a[i++] = value; //append elements in array
}while(value>=0);
i--;
cout<<"\nArray are:"<<endl;//message for array
for(int k = 0;k<i;k++){ //set for loop
cout<<a[k]<<" "; //print array
}
return 0;
}
<u>Output</u>:
Enter less than 0 to exit:
Enter the integer numbers:
1
2
3
4
5
-1
Array are:
1 2 3 4 5
Explanation:
Here, we set the integer data type main method "main()" and inside it:
- we set integer type array variable with index value 100.
- we set two integer type variable "value" and "i" initialize value 0.
- we set the do-while loop in which we get the input from the user and and append in the array and pass condition if the value is greater then equal to 0.
- Finally, set for loop and print the elements of an array.
What happens when you click answer questions? If nothing happens, exit out or restart, it’s a glitch.
B. Add actions
A. a presentation without a clear beginign middle and end
A. add action between slides