Write a program which converts an input integer representing a number in base 10 to the corresponding number in base 14

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Write a program which converts an input integer representing a number in base 10 to the corresponding number in base 14

Post by answerhappygod »

Write A Program Which Converts An Input Integer Representing A Number In Base 10 To The Corresponding Number In Base 14 1
Write A Program Which Converts An Input Integer Representing A Number In Base 10 To The Corresponding Number In Base 14 1 (163.39 KiB) Viewed 51 times
I already completed the problem and did the beginning, but howwould I warn that the input converted to base 14 has more than4 digits and is too large? What do I need to change?
CODE:
#include <stdio.h>#include <stdlib.h>
int main() { // User input int num; printf("Enter a number: "); scanf("%d", &num);
// Declare an array char *ans = malloc(sizeof(char) * 5); int temp = num;
int i = 0; while (temp /= 14) { i++; }
ans[i + 1] = '\0'; // Converting the input in base 10 to base 14 while (num) { // Taking out MSB int rem = num % 14; // If MSB < 10 then equal to char value from 0 to 9 if (rem > 9) ans[i--] = 55 + rem; else ans[i--] = 48 + rem; num /= 14; } if (ans == 0) { // if overflow printf("In base 14: %s", ans); } else printf("That number is too large!\n"); return 0;}
Output:
Enter a number: 38416In base 14: 10000
Should be:
Enter a number: 38416That number is too large!
Write a program which converts an input integer representing a number in base 10 to the corresponding number in base 14 using an array. In base 14, the digits after are ABCD. Your program only needs to consider up to 4 digit base 14 numbers. If an input would convert to a number in base 14 with more than 4 digits, warn the user. Requirements - The array size should be 4. - The input should be read as an Example Runs Enter a number: 26 In base 14: 1C Enter a number: 38415 In base 14: DDDD Enter a number: 38416 That number is too large!
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply