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# language Write a program that takes in a number from the user. Then it prints...
c# language Write a program that takes in a number from the user. Then it prints a statement telling the user if the number is even or odd. If the number is odd, it counts down from the number to 0 and prints the countdown on the screen, each number on a new line. If the number is even, it counts down from the number to 0, only even numbers. For example, if the user enters 5, the output will...
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...
5. Write a CH program that takes the marks of a student as input and prints...
5. Write a CH program that takes the marks of a student as input and prints the grade on screen according to the following criteria: CRITERIA LESS THAN 60 GREATER THAN 60 BUT LESS THAN 65 GREATER THAN 65 BUT LESS THAN 70 GREATER THAN 70 BUT LESS THAN 75 GREATER THAN 75 BUT LESS THAN 80 GREATER THAN 80 BUT LESS THAN 85 GREATER THAN 85 BUT LESS THAN 90 GREATER THAN 90 GRADE F D D+ с C+...
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...
Problem: Write a program that takes your weight in pounds as input and then prints how...
Problem: Write a program that takes your weight in pounds as input and then prints how much you will weigh on Moon and Mars. The formula to convert weight on the Earth to weight on Moon and Mars are given below: Weight on Moon = weight on Earth * 0.165 Weight on Mars = weight on Earth * 3.711 / 9.81 You should name the program as weight_watcher.py. The output should look like as shown below:
- 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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT