📌  相关文章
📜  程序将厘米转换成像素

📅  最后修改于: 2021-04-30 02:10:31             🧑  作者: Mango

给定一个整数厘米(代表以厘米为单位的长度),任务是将其转换为以像素为单位的等效值。

例子:

方法:可以根据以下数学关系来解决问题:

下面是上述方法的实现:

C++
// C++ program to convert centimeter to pixels
#include 
using namespace std;
  
// Function to convert
// centimeters to pixels
void Conversion(double centi)
{
  
    double pixels = (96 * centi) / 2.54;
    cout << fixed << setprecision(2) << pixels;
}
  
// Driver Code
int main()
{
  
    double centi = 15;
    Conversion(centi);
    return 0;
}


Java
// Java program to convert
// centimeter to pixels
  
import java.io.*;
  
class GFG {
  
    // Function to convert
    // centimeters to pixels
    static double Conversion(double centi)
    {
        double pixels = (96 * centi) / 2.54;
        System.out.println(pixels);
        return 0;
    }
  
    // Driver Code
    public static void main(String args[])
    {
        int centi = 15;
        Conversion(centi);
    }
}


Python3
# Python program to convert
# centimeters to pixels 
  
# Function to convert
# centimeters to pixels 
def Conversion(centi):
  
    pixels = ( 96 * centi)/2.54 
    print ( round(pixels, 2)) 
# Driver Code 
centi = 15
Conversion(centi)


C#
// C# program to convert
// centimeter to pixels
using System;
  
class GFG {
  
    // Function to convert
    // centimeter to pixels
    static double Conversion(double centi)
    {
        double pixels = (96 * centi) / 2.54;
        Console.WriteLine(pixels);
        return 0;
    }
  
    // Driver Code
    public static void Main()
    {
        double centi = 15;
        Conversion(centi);
    }
}


PHP


输出:
566.93

时间复杂度: O(1)
辅助空间: O(1)