Question

Hi need to design a programm in C++ which reset the output format,i.e Display the number of floating point numbers in th...

Hi need to design a programm in C++ which reset the output format,i.e Display the number of floating point numbers in the fixed point format according to the system default format. First the Input should be the number of test cases, and then input the test cases.

For example:

Input:

4 //number of test cases
2123.324423
2123.324423
2123.324423
123.0000

Output:

2123.32
2123.324423
2123.32
2123.324423
2123.32
2123.324423
123
123.000000
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--){
  
double f;
cin>>f;
int t=0;
if(f==(double)(int)f){
t=1;
  
}
  
if(t==0)
{
cout << fixed << setprecision(2) <<f<<"\n";
cout << fixed << setprecision(6) <<f<<"\n";
}
else
{
cout << fixed << setprecision(0) <<f<<"\n";
cout << fixed << setprecision(6) <<f<<"\n";
}
}
}

Add a comment
Know the answer?
Add Answer to:
Hi need to design a programm in C++ which reset the output format,i.e Display the number of floating point numbers in th...
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
  • Write a program that takes an operation (+, -, /, or *) and two floating-point numbers,...

    Write a program that takes an operation (+, -, /, or *) and two floating-point numbers, and outputs the result of applying that operation to the two numbers. For example, if the input is: + 100 3.14 the output should be 100 + 3.14 = 103.14 Likewise, if the input is * 4 5 the output should be 4 * 5 = 20 You may assume the input is well-formed; that is, the first string is one of the four...

  • C++ ONLY Write a function calculator that takes two floating numbers and one operator and prints...

    C++ ONLY Write a function calculator that takes two floating numbers and one operator and prints out the answer based on arithmetic. Assume that there are no overflow, underflow and division by zero cases. Your function should be named calculator Your function takes three input parameter: two double numbers and one char operator Your function does not return anything Your function prints answer in the format specified below Your function should set precision point to 2 Note: You must use...

  • Hi, PLEASE I need the code in C programming, (USING THE SAME INPUT AND OUTPUT FORMAT...

    Hi, PLEASE I need the code in C programming, (USING THE SAME INPUT AND OUTPUT FORMAT DESCRIBED BELOW). Title: Game of Life Description In this assignment, you will code a simulation called "Game of Life". It is a very famous 'game' and the formed the basis of an entire field of simulation models called "cellular automata". Before continuing reading this assignment, I suggest you read a bit more about Game of Life at: https://en.wikipedia.org/wiki/Conway's_Game_of_Life or http://www.math.com/students/wonders/life/life.html (the latter also has...

  • To write a C program (not C++) that converts numbers between Decimal and IEEE-754 format and...

    To write a C program (not C++) that converts numbers between Decimal and IEEE-754 format and vice versa. Inputs: Number in Decimal format (including special case of 0) Number in IEEE-754 format (including special cases) Output: Equivalent number in IEEE-754 format Equivalent number in Decimal Specification: The program converts a number based on choosing from a menu of choices, where each choice calls the appropriate procedure, where the choices are: Decimal to IEEE-754 conversion IEEE-754 to Decimal conversion Quit program...

  • PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a...

    PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a function yesOrNo which has no parameters. When called, it gets input from the user until the user types either 'yes' or 'no', at which point the function should return True if the user typed 'yes' and False if the user typed 'no'. Any other entries by the user are ignored and another value must be input. For example: Test Input Result print(yesOrNo()) hello blank...

  • Instructions Write a C++ program that performs the following: Accept a list of floating point values...

    Instructions Write a C++ program that performs the following: Accept a list of floating point values on a single line (separated by spaces). This is vector A. The user may enter as many values as they desire. Accept a second list of floating point values on a single line (separated by spaces). This is vector B. The user may enter as many values as they desire. There is no requirement that the two vectors have the same number of elements....

  • In C PLEASE 1.22 LAB: Using math functions Given three floating-point numbers x, y, and z,...

    In C PLEASE 1.22 LAB: Using math functions Given three floating-point numbers x, y, and z, output x to the power of z, x to the power of (y to the power of 2), the absolute value of y, and the square root of (xy to the power of z). Output each floating-point value with two digits after the decimal point, which can be achieved as follows: printf("%0.21f", yourValue); Ex: If the input is: 5.0 6.5 3.2 the output is:...

  • Write a C function called display_dollar which takes a floating point number as input, and displays...

    Write a C function called display_dollar which takes a floating point number as input, and displays this is a dollar value to the screen. This means that it should have a ‘$’ in front of it, and be displayed to exactly two decimal places in non-scientific form. Your function should not put spaces or newlines before or after the output?

  • Please show that it works and show the output. Description Develop a program (in C++) that...

    Please show that it works and show the output. Description Develop a program (in C++) that first asks the user to input a signed number, for example 48, then converts it to binary number by using Two's Complement regulations. Do the same for the second inputted number, eg. 17. Then compute the summation of these two numbers, output the results in binary format first, then if there is an overflow, display error message; otherwise, convert the result to decimal value...

  • C++ Addition of Complex Numbers Background Knowledge A complex number can be written in the format of , where and are real numbers.   is the imaginary unit with the property of .   is called the r...

    C++ Addition of Complex Numbers Background Knowledge A complex number can be written in the format of , where and are real numbers.   is the imaginary unit with the property of .   is called the real part of the complex number and   is called the imaginary part of the complex number. The addition of two complex numbers will generate a new complex number. The addition is done by adding the real parts together (the result's real part) and adding the...

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
ADVERTISEMENT