Question

SOLVE IN C: Given a double, create a program that can round up AND down to...

SOLVE IN C: Given a double, create a program that can round up AND down to the nearest integer WITHOUT using the built in round() function. No built in math library functions are allowed.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the C program for round the given double number without using round() function & math Library function

Code:

#include<stdio.h>
int main(void)
{
double v;
int con, r_value, mul;
printf("Please enter a value to be rounded: ");
scanf("%lf", &v);
mul=v*10;
con=mul%10;
r_value=mul/10;
if(con>=5)
r_value=r_value+1;
else
r_value=r_value;
printf("The rounded value is %.2d", r_value);

return 0;
}

Output:

Please enter a value to be rounded: 10.567

The rounded value is 11

Output Snapshots:

Please given Thumbs Up.....

Add a comment
Know the answer?
Add Answer to:
SOLVE IN C: Given a double, create a program that can round up AND down to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Resampling: Do not use any in-built functions from opencv and numpy. In general, you can use...

    Resampling: Do not use any in-built functions from opencv and numpy. In general, you can use function from math library. Functions allowed for this part are: np.array(), np.matrix(), np.zeros(), np.ones(), cv2.imread(), cv2.namedWindow(), cv2.waitKey(). Write code for zooming and shrinking an image using the nearest neighbor and bilinear interpolation. The input to your program is: (i) image, (ii) transformation parameters, and (iii) interpolation method. (Can I get more of an explanation and puesdocode of how you use nearest neighbor and bilinear...

  • CE – Return and Overload in C++ You are going to create a rudimentary calculator. The...

    CE – Return and Overload in C++ You are going to create a rudimentary calculator. The program should call a function to display a menu of three options: 1 – Integer Math 2 – Double Math 3 – Exit Program The program must test that the user enters in a valid menu option. If they do not, the program must display an error message and allow the user to reenter the selection. Once valid, the function must return the option...

  • Write a program that contains a main function, a “double custom_operator_function(int op_type, double x, double y)”,...

    Write a program that contains a main function, a “double custom_operator_function(int op_type, double x, double y)”, a “double min(double,double)”, a double max(double x,double y), and a double pow(double x, int y). The main function is used to call the custom operator function. Next, the custom operator function calls the min/max/pow functions based on the op_type. From the main, call the custom operator function with the three inputs 1/-3/5, 2/4/5, and 3/4/5. Print the result of each input to screen. i)...

  • write a Matlab program ( solve the three questions). please use array and create your own...

    write a Matlab program ( solve the three questions). please use array and create your own function to check primality Question 1 : [10 points) Write a MATLAB program that will store all the first 1000 prime numbers in an array variable named arr_of_primes. Please note that a prime number is a positive integer that is bigger than or equal to 2 which is divisible only by 1 and itself. Examples of the first 8 primes are: 2, 3, 5,...

  • Write a C program to create the double arrays A and B, using the gen rand...

    Write a C program to create the double arrays A and B, using the gen rand mat function.

  • code in C++ Create a program that uses the pass by reference operator instead of the...

    code in C++ Create a program that uses the pass by reference operator instead of the return command. Your main program will need to: create empty variables call void function 1 with no input to display your name to the screen call function 2 to collect the square feet that a gallon of paint covers from user call function 2 to collect the square feet of wall that needs to be painted call function 3 to calculate the number of...

  • Create a CPP file for a C++ Program. Write exactly these functions, power(x,y) function and a...

    Create a CPP file for a C++ Program. Write exactly these functions, power(x,y) function and a print(text, number) function and the main() function. The power(x,y) function returns an integer result that is calculated by raising a number x (integer) to a power y (integer). The second argument y (exponent) of the function can not exceed 100. If the second argument exceeds 100, the function should return -1. Your power(x,y) function must be able to take either 1 or 2 integer...

  • Write the Code in C program. Create a random password generator that contains a user-specified number...

    Write the Code in C program. Create a random password generator that contains a user-specified number of characters. Your program should prompt the user for the desired length of the password. Length of password: To create your password, use the random number generator in the stdlib.h C library. To generate random numbers, you will need the srand() and rand() functions. srand(seed) is used to "seed" the random number generator with the given integer, seed. Prompt the user for the seed...

  • Create a C++ program that fulfills the requirements of the following prompt: This program will create...

    Create a C++ program that fulfills the requirements of the following prompt: This program will create a text-based squad versus squad battling game. The game will be set up so that two players can play and each player will control a squad. Each member of the squad will have basic and special abilities. When one squad has been fully defeated, that player will be declared the loser. The program will then exit. The basis of this program will require the...

  • Please solve this coding in C++ language. Create a library with the following functions (prototypes and...

    Please solve this coding in C++ language. Create a library with the following functions (prototypes and descriptions are given): - double energyToHeatWater(double mass, double deltaT); // returns the heat, in joules, required to heat “mass” (in grams) of liquid water at atmospheric pressure by “deltaT” degrees C. The function should limit the maximum deltaT to 100C as a larger value is not possible for liquid water at atmospheric pressure. - double energyToBoilWater(double mass); // returns the heat, in joules, required...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT