Algorithm


Problem Name: beecrowd | 2758

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2758

Floating Number Input and Output

 

By Roberto A. Costa Jr, UNIFEI BR Brazil

Timelimit: 1

Your teacher would like to make a program with the following characteristics:

  1. Create two variables to store real numbers of simple precision;
  2. Create two variables to store double precision real numbers;
  3. Read the first simple precision number that will always have a decimal;
  4. Read the second simple precision number that will always have two decimal places;
  5. Read the first double precision number that will always have three decimal places;
  6. Read the second double precision number that will always have four decimal places;
  7. Print the letter A, a blank, the equals sign, a blank, the number stored in the first variable read in step 3, a comma, a blank, the letter B, a blank, the sign of equal, a space, the number stored in the second variable read in step 4. Do not forget to skip line;
  8. Print the letter C, a blank, the equal sign, a blank, the number stored in the first variable read in step 5, a comma, a blank, the letter D, a blank, the sign of equal, a space, the number stored in the second variable read in step 6. Do not forget to skip line;
  9. Repeat procedure 7, printing the numbers with one decimal place;
  10. Repeat procedure 8, printing the numbers with one decimal place;
  11. Repeat procedure 7, printing the numbers to two decimal places;
  12. Repeat procedure 8, printing the numbers to two decimal places;
  13. Repeat procedure 7, printing the numbers to three decimal places;
  14. Repeat procedure 8, printing the numbers to three decimal places;
  15. Repeat procedure 7, printing the numbers to three decimal places and in the form of scientific notation with the character E;
  16. Repeat procedure 8, printing the numbers to three decimal places and in the form of scientific notation with the character E;
  17. Repeat procedure 7, printing only the whole part of the number;
  18. Repeat procedure 8, printing only the entire part of the number.

 

Input

 

The input consists of several test files. Each test file has two rows. In the first line there are two real numbers A and B (-1000.0 ≤ A, B ≤ 1000.0), separated by white space. In the second line there are two real numbers C and D (-1000.0 ≤ C, D ≤ 1000.0), separated by white space. As shown in the following input example.

 

Output

 

For each file in the input, you have an output file. The output file has twelve rows as described in item 7 and 8. As shown in the following output example.

 

 

 

Input Samples Output Samples

1.2 3.45

3.451 3.4516

A = 1.200000, B = 3.450000

C = 3.451000, D = 3.451600

A = 1.2, B = 3.5

C = 3.5, D = 3.5

A = 1.20, B = 3.45

C = 3.45, D = 3.45

A = 1.200, B = 3.450

C = 3.451, D = 3.452

A = 1.200E+00, B = 3.450E+00

C = 3.451E+00, D = 3.452E+00

A = 1, B = 3

C = 3, D = 3

 

 

 

2127.9 -821.45

-1020.456 1352.4548

A = 2127.899902, B = -821.450012

C = -1020.456000, D = 1352.454800

A = 2127.9, B = -821.5

C = -1020.5, D = 1352.5

A = 2127.90, B = -821.45

C = -1020.46, D = 1352.45

A = 2127.900, B = -821.450

C = -1020.456, D = 1352.455

A = 2.128E+03, B = -8.215E+02

C = -1.020E+03, D = 1.352E+03

A = 2128, B = -821

C = -1020, D = 1352

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h&t;
int main(){ 
  float A, B; 
  double C, D; 
  char STR[10]; 

  scanf("%f%f%lf%lf",&A,&B,&C,&D); 

  printf("A = %f, B = %f\nC = %lf, D = %lf\n",A, B, C, D); 
  printf("A = %.1f, B = %.1f\nC = %.1lf, D = %.1lf\n",A, B, C, D); 
  printf("A = %.2f, B = %.2f\nC = %.2lf, D = %.2lf\n",A, B, C, D); 
  printf("A = %.3f, B = %.3f\nC = %.3lf, D = %.3lf\n",A, B, C, D); 
  sprintf(STR,"%.3E",A); STR[9] = '\0'; 
  printf("A = %s,",STR);
  sprintf(STR,"%.3E",B); STR[9] = '\0'; 
  printf(" B = %s\n",STR); 
  sprintf(STR,"%.3lE",C); STR[9] = '\0'; 
  printf("C = %s,",STR); 
  sprintf(STR,"%.3lE",D); STR[9] = '\0'; 
  printf(" D = %s\n",STR);
  printf("A = %d, B = %d\nC = %d, D = %d\n",(int)A,(int)B,(int)C,(int)D); 

  return 0;
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
1.2 3.45 3.451 3.4516

Output

x
+
cmd
A = 1.200000, B = 3.450000 C = 3.451000, D = 3.451600 A = 1.2, B = 3.5 C = 3.5, D = 3.5 A = 1.20, B = 3.45 C = 3.45, D = 3.45 A = 1.200, B = 3.450 C = 3.451, D = 3.452 A = 1.200E+00, B = 3.450E+00 C = 3.451E+00, D = 3.452E+00 A = 1, B = 3 C = 3, D = 3

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    float a, b;
    double c, d;
    cin >> a >> b >> c >> d;
    cout << "A = " << fixed << a << ", B = " << fixed << b << endl;
    cout << "C = " << fixed << c << ", D = " << fixed << d << endl;
    cout << "A = " << setprecision(1) << a << ", B = " << setprecision(1) << b << endl;
    cout << "C = " << setprecision(1) << c << ", D = " << setprecision(1) << d << endl;
    cout << "A = " << setprecision(2) << a << ", B = " << setprecision(2) << b << endl;
    cout << "C = " << setprecision(2) << c << ", D = " << setprecision(2) << d << endl;
    cout << "A = " << setprecision(3) << a << ", B = " << setprecision(3) << b << endl;
    cout << "C = " << setprecision(3) << c << ", D = " << setprecision(3) << d << endl;
    cout << "A = " << scientific << uppercase << setprecision(3) << a << ", B = " << setprecision(3) << b << endl;
    cout << "C = " << setprecision(3) << c << ", D = " << setprecision(3) << d << endl;
    cout << fixed;
    cout << "A = " << setprecision(0) << a << ", B = " << setprecision(0) << b << endl;
    cout << "C = " << setprecision(0) << c << ", D = " << setprecision(0) << d << endl;
    return 0;
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
1.2 3.45 3.451 3.4516

Output

x
+
cmd
A = 1.200000, B = 3.450000 C = 3.451000, D = 3.451600 A = 1.2, B = 3.5 C = 3.5, D = 3.5 A = 1.20, B = 3.45 C = 3.45, D = 3.45 A = 1.200, B = 3.450 C = 3.451, D = 3.452 A = 1.200E+00, B = 3.450E+00 C = 3.451E+00, D = 3.452E+00 A = 1, B = 3 C = 3, D = 3
Advertisements

Demonstration


Previous
#2757 Beecrowd Online Judge Solution 2757 Input and Output of Integers Solution in C, C++, Java, Js and Python
Next
#2759 Beecrowd Online Judge Solution 2759 Input and Output Character Solution in C, C++, Java, Js and Python