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...
Write a program that performs the following tasks: Display a friendly greeting to the user Prompt the user for the value to convert (a String) Accept that String Prompt the user for the value of the initial base (an integer) Accept that integer Prompt the user for the desired base of the output (an integer) Accept that integer If the String is not a legal expression of a number in the initial base, display an error message and exit the...
Comp Sci JAVA Log program using controls and loops 1. (1 point) Asks the user to enter an integer base b > 1. (1 point) If the user enter anything less than or equal to 1, you should quit the program. 2. (1 point) Asks the user to enter a positive integer x greater than 0. (2 points) If the user enter anything less than or equal to 0, you should keep asking the user to re-enter a new number...
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...
Java Code please read comments and add the code to required lines....LINE 1 to LINE 5 ********************************************************************** * Program Summary: This program demonstrates these basic Java concepts: * - Creating an array based on user input * - Accessing and displaying elements of the array * * The program should declare an array to hold 10 integers. * The program should then ask the user for an integer. * The program should populate the array by assigning the user-input integer...
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)
{...
I need help getting my program to reject a negative input from the user. Here is what I have: #short description of what the program will do print("Hello, this program will ask you to enter a non-negative decimal integer. The program will then show the binary equivalent of the integer you choose.") #ask the user to enter the non-negative decimal integer number= int(input("Enter a non-negative decimal integer: ")) while number< 0: print("Number Cannot Be Negative!! Try again...") #create a variable...
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...