[C_MM05-易] 計算正方形面積
JAVA- import java.util.*;
- import java.lang.*;
- import java.io.*;
- class Main
- {
- public static void main (String[] args) throws java.lang.Exception
- {
- double length, square_area;
- Scanner sc = new Scanner(System.in);
- for(int i = 0;i < 50;i++)
- {
- length = sc.nextDouble();
- square_area = length * length;
- System.out.printf("%.1f",square_area);
- System.out.println();
- }
- }
- }
C++
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- int main() {
- double square;
- while(cin >> square)
- {
- square = square * square;
- square = square * 10 + 0.5;
- square = floor(square);
- square = square / 10;
- cout << fixed << setprecision(1) << square << endl;
- }
- return 0;
- }
沒有留言:
張貼留言