from the given data
# include < stdio.h >
# include < string.h>
void base 10 ti any base(
int num, int base, char * converted _str)
{
int index = 0;
int length =0;
int rem = 0;
char result (32) = {0};
// loop till num is greater than 0
while (num > 0)
{
rem = ( num % base);
// calculate remainder using modulus operator
num = num/ base
// divide the number by base
if (base >= 16 && rem > 9)
// if base is >= 16 and remainder > 9
result (index ++) = rem + `A` -10;
// add ascii value of A and subtract 10 to offset 0-9
else
result (index ++) = rem + `0`;
// remainder <= 9, just add ascii value `0`
}
// ned to reverse the result to get correct converted string
// loop till index > 0, index is length of the result string
while (index > 0)
{
// put the character starting from index to 0 in converted _str from 0
// increment length and decrement index
converted_str(length++) = result (-- index);
}
}
int main()
{
int num = 0;
int base = 0;
char converted _str (32) =(0);
// prompt for base 10 number
printf(" \n Enter the base 10 number you would like to convert;");
scanf("%d", & num);
// loop till valid base not entered
while (1)
{
// prompt for base value
printf(" Enter the base you would like to convert %d to : ", num);
scanf("%d", & base);
if (!(base > = 2 && base <= 36))
{
// continue if invalid base entered
printf(" invalid base value. please enter the base >= 2 and <= 36);
continue;
}
else
{
break;
}
}
return0;
}
please add comments and make the progrom work with negative and simple as much as possible...
Implement a Java program using simple console input & output and logical control structures such that the program prompts the user to enter 5 integer scores between 0 to 100 as inputs and does the following tasks For each input score, the program determines whether the corresponding score maps to a pass or a fail. If the input score is greater than or equal to 60, then it should print “Pass”, otherwise, it should print “Fail”. After the 5 integer...
For Python: A prime number is defined as an integer greater than 1 that has no positive divisors other than 1 and itself. Write a program that prompts the user for an integer > 1. Validate the value is > 1 (if not, ask for another). Use a loop to determine if the number is prime or not. Issue an appropriate message. [complete this part before proceeding]. Add a loop that continues to ask the user if they would like...
Here is the code I made, but the test case is not working, it goes wrong when the binary string convert to decimal. please help. #include "stdafx.h" #include <iostream> #include <string> #include <math.h> #include <locale> using namespace std; // function for option 1 void decToBin(int number) { int array[16]; int i = 0; for (int counter = 0; counter < 16; counter++) { array[counter] = 0; } while (number > 0) {...
C++ with comments please! // numberverifier.cpp #include <iostream> #include <exception> using std::cout; using std::cin; using std::endl; #include <cmath> #include <cstring> class nonNumber : public exception { public: /* write definition for the constructor */ -- Message is “An invalid input was entered” }; int castInput( char *s ) { char *temp = s; int result = 0, negative = 1; // check for minus sign if ( temp[ 0 ] == '-' ) negative = -1; for ( int i...
Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...
IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...
(Python) Please do NOT solve it by using special functions(like max min, divmod), I have to ask the same questions again and again otherwise, thanks for your understanding. 1. Write a program that prompts the user for an integer, calculates the factorial of the input integer and displays the result as a string with a comma at every third position, starting from the right. Assume that user input is valid. Hint: Think about representing a number as a string. Sample...
In C please : The tasks in this exam review exercise are structured in levels. You can see the point distribution for the levels at the end. It is strongly recommended that you ensure you have passed all test cases of lower levels before moving up to a higher level. For example, ensure you have completed all Level 0 and 1 tasks before even looking at Level 2 Tasks. MESSAGE ENCODER LEVEL 0: (test cases - 50 points) Start by...
You work at a bank and needs to automate the bills that are given to a customer when they cash a check. When the check is cashed, the system should automatically break down the dollar amount into the smallest number of $20, $10, $5, and $1 bills. Specifications: Write a program that prompts the user to enter a U.S dollar amount and then shows how to pay the customer using the smallest number of bills. After the program runs, prompt...
This homework is an approach to generating random numbers. In this technique a seed value is used to construct a new (seemingly random) value in the following manner: The seed, s, is written down in n-bit binary. Several bit positions, called taps, are used to generate a feedback bit. Bit n-1 is always one of the taps. The feedback bit, f is the exclusive-or of the tap bit values The seed is shifted to the left...