Question

In: Computer Science

I have below code! I would like to to convert the larger variable to hex and...

I have below code! I would like to to convert the larger variable to hex and get len() of larger once it's in hex format.

Example: if larger number is 900000 then the hex is DBBA0 then len of DBBA0 is 5. I need everything save in new variable!

It's in C.

// Function to find largest element

int largest(int a[], int n)

{

    int large = a[0], i;

    for(i = 1; i < n; i++)

    {

        if(large < a[i])

            large = a[i];

    }

    return large;

}

Solutions

Expert Solution

Program :

#include <stdio.h>
void largest(int a[],int);
void hexadecimal(int);
int main()
{
int i,n,a[100];
printf("How values do wwant to enter:");
scanf("%d",&n);
  
for(i=0;i<n;i++)
scanf("%d",&a[i]);
largest(a,n);

return 0;
}
void largest(int a[], int n)
{

int large = a[0], i;
for(i = 1; i < n; i++)
{

if(large < a[i])
large = a[i];

}
printf("\nThe largest value is:%d",large);
decToHexa(large);

}
void decToHexa(int n)
{
  
char hex[100];
int i = 0,c=0;
while(n!=0)
{

int t = 0;
t = n % 16;
if(t < 10)
{
hex[i] = t + 48;
i++;
}
else
{
hex[i] = t + 55;
i++;
}
  
n = n/16;
}
printf("\nhexadecimal value is:");
for(int j=i-1; j>=0; j--)
{
printf("%c", hex[j]);
c++;
}
printf("\nThe length of hexa decimal vlaue is : %d",c);
}
  
out put of the program :


Related Solutions

Hi, I need the HTML5 code for the below. About Me **Would like to add a...
Hi, I need the HTML5 code for the below. About Me **Would like to add a image of a plane or something related to travel here. Mia Jo I am taking this class to earn my Computer programmer CL1. Things I Like to Do: Spend time with family Traveling People Watch Places I Want to Go or Have Visited: Dubai- December'18 Enjoyed shopping and the desert safari the most. Cuba- August '18 Enjoyed learning about the culture and history. China-...
I would like to know about the larger picture, current state and future prospects of the...
I would like to know about the larger picture, current state and future prospects of the sequence of papers that were written by Sheldon Katz and Cumrun Vafa on F-theory. (Freddy Cachazo was also a co-author in many of these papers) I guess the same is also known as "geometric engineering". (Kindly explain if that is not the same) There have been recent works on F-theory by Cumrum Vafa, Jonathan Heckman and others. I would like to know of how...
In YASM Assembly language, how would you convert a hex byte into it's ascii representation?
In YASM Assembly language, how would you convert a hex byte into it's ascii representation?
I would like the following code in PYTHON please, there was a previous submission of this...
I would like the following code in PYTHON please, there was a previous submission of this question but I am trying to have the file save as a text file and not a json. Any help would be greatly appreciated. Create an application that does the following: The user will enter product codes and product numbers from the keyboard as strings. The product code must consist of four capital letters. The product number can only consist of numeric characters, but...
In Python I have a code: here's my problem, and below it is my code. Below...
In Python I have a code: here's my problem, and below it is my code. Below that is the error I received. Please assist. Complete the swapCaps() function to change all lowercase letters in string to uppercase letters and all uppercase letters to lowercase letters. Anything else remains the same. Examples: swapCaps( 'Hope you are all enjoying October' ) returns 'hOPE YOU ARE ALL ENJOYING oCTOBER' swapCaps( 'i hope my caps lock does not get stuck on' ) returns 'I...
1. Given the 8 bit hex number 0x5E, what smallest hex value would you have to...
1. Given the 8 bit hex number 0x5E, what smallest hex value would you have to add to set the Overflow flag? 2. Given the 8 bit hex number 0x6E, what smallest hex value would you have to add to set the Carry Flag? Please give detailed explanation on how to solve.
Can I get some assistance with this request. Right now the code that converts a hex...
Can I get some assistance with this request. Right now the code that converts a hex character read on input into its decimal value is in the main routine. To make the main routine easier to read, make the conversion code concise and reusable, move it into a function named hex2Dec. The hex2Dec function should take a character parameter which is the character read from input. The function should return an integer which is the converted decimal value of the...
the purpose of the code is to implement a stack how can i convert this code...
the purpose of the code is to implement a stack how can i convert this code in a way that these changes apply to it? // simplify the logic of the main // getline(cin, line) needs to be changed to a normal cin >> line; //make a function for 'list' // not allowed temporary stack (stack s2) //merge the catches (errors) // introduce another function for main // avoid repetitive code here is the code: #include #include #include #include #include...
I would like a reflective description of the organs below if I went to an educational...
I would like a reflective description of the organs below if I went to an educational exhibition and saw these organs that exposes the inner workings of human anatomy Please Type and not handwritten the response. Thank you. Organ Personalized statement about the organ if I saw it in person. Appendix bladder Brain bronchi Esophagus Heart Kidneys Large intestine larynx Liver Lungs Nasal Cavity Nerves Ovary Pancreas pharynx Rectum Small intestine Spinal Cord Stomach Thyriod Gland Uterus
I am using NetBeans IDE Java for coding. I would like the code to be commented...
I am using NetBeans IDE Java for coding. I would like the code to be commented for a better understanding. 1. Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is located at a point with integer coordinates and faces north, east, south, or west. Supply methods: public void turnLeft() public void turnRight() public void move() public Point getLocation() public String getDirection() The turnLeft and turnRight methods change the direction but not the location....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT