Question

In: Computer Science

Write a program in C that takes as input a four-digit hexadecimal number and prints the...

Write a program in C that takes as input a four-digit hexadecimal number and prints the next

10 hexadecimal numbers. Define a hexadecimal number as

int hexNum[4]

Allow upper- or lowercase letters for input and use uppercase letters for the hexadecimal

output. For example, 3C6f should be valid input and should produce output 3C6F, 3C70,

3C71, . . . .

Solutions

Expert Solution

If you have any doubts, please give me comment...

#include<stdio.h>

#include<math.h>

#include<ctype.h>

int convertToDecimal(char hex[]){

    int i=0, n=4;

    int decimal = 0;

    while(hex[i]!='\0'){

        hex[i] = toupper(hex[i]);

        if(hex[i]>='A' && hex[i]<='F')

            decimal += (hex[i]-'A'+10)*pow(16, n-i-1);

        else

            decimal += (hex[i]-'0')*pow(16, n-i-1);

        i++;

    }

    return decimal;

}

void convertToHex(int n, char hex[]){

    int i=4;

    while(n!=0){

        int r = n%16;

        if(r>=10)

            hex[i-1] = r+'A'-10;

        else

            hex[i-1] = r+'0';

        n/=16;

        i--;

    }

    hex[4] = '\0';

}

int main(){

    char hexNumber[4];

    printf("Enter your input: ");

    scanf("%s", hexNumber);

    int decimal = convertToDecimal(hexNumber);

    char next[4];

    printf("The next 10 hexadecimal numbers are: \n");

    for(int i=0; i<10; i++){

        convertToHex(decimal+i, next);

        printf("%s\n", next);

    }

    return 0;

}


Related Solutions

Write a program in C that takes as input an 8-bit binary number and prints the...
Write a program in C that takes as input an 8-bit binary number and prints the next 10 binary numbers. Define a binary number as int binNum[8]; Use binNum[0] to store the most significant (i.e., leftmost) bit and binNum[7] to store the least significant bit. Ask the user to input the first binary number with each bit separated by at least one space.
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Important! Consider which control structures will work best for which aspect of the assignment. For example, which would be the best to use for a menu?...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Your code must contain at least one of all of the following control types: nested for() loops a while() or a do-while() loop a switch() statement...
Write a Java program that takes in a string and a number and prints back the...
Write a Java program that takes in a string and a number and prints back the string from the number repeatedly until the first character... for example Pasadena and 4 will print PasaPasPaP. Ask the user for the string and a number Print back the string from the number repeatedly until the first character For both programs please utilize: methods arrays loops Turn in screenshots
Text Wrap Problem Write a program in Python that takes an input string and prints it...
Text Wrap Problem Write a program in Python that takes an input string and prints it as multiple lines of text such that no line of text is greater than 13 characters and words are kept whole. For example, the first line of the Gettysburg address: Four score and seven years ago our fathers brought forth upon this continent a new nation, conceived in liberty and dedicated to the proposition that all men are created equal Becomes: Four score and...
- sparc assembly - *Write a program that takes four 32-bit integers (A,B,C,D) in hexadecimal form...
- sparc assembly - *Write a program that takes four 32-bit integers (A,B,C,D) in hexadecimal form and calculates A*B + C*D. (Assumption: User input is 32-bit 0 or positive. The result is expressed in 64 bits.) [result example] bash $ assm Hex value? ffffffff Hex value? 8 Hex value? ffffffff Hex value? 8 Result is 0000000f fffffff0
Python Write a program that takes a text filename as command line argument, and prints number...
Python Write a program that takes a text filename as command line argument, and prints number of times each letter occurred in this file.
Write a short C++ program that takes all the lines input to standard input and writes...
Write a short C++ program that takes all the lines input to standard input and writes them to standard output in reverse order. That is, each line is output in the correct order, but the ordering of the lines is reversed. Please use vector datatype standaard library #include <vector> Thanks
Write a C program that, given a file named Program_2.dat as input, determines and prints the...
Write a C program that, given a file named Program_2.dat as input, determines and prints the following information: The number of characters in the file. The number of uppercase letters in the file. The number of lowercase letters in the file. The number of words in the file. The number of lines in the file. Your program should assume that the input file, Program_2.dat, may contain any text whatsoever, and that text might be, or might not be, the excerpt...
C++ Write a program that takes a string and integer as input, and outputs a sentence...
C++ Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is "quit". If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps your doctor away. Eating 2 shoes a day keeps your doctor away.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT