问题:我总共有50卢比,我购买3种产品,每种产品的价格都不同。当我购买产品时,我会写王子i-e Price_Remaining和Price_Consume。最终,当我同时计算两个列表时,我在一侧得到50,而在另一侧得到51?
实际上这是一个数学问题,但是我用C#代码实现了这一点,而且我个人不知道为什么我一方面得到50,另一方面得到51?如果有人知道:与我分享。 (谢谢)
所有问题的详细信息都在代码注释中给出。
namespace Fifty_And_FiftyOne_Problem
{
class Program
{
static void Main(string[] args)
{
int TotalRupees = 50; // Rs.50/-
int Sum_Of_totalConsume = 0;
int Sum_Of_totalRemaining = 0;
// Comsume.
List<int> totalOfCosume = new List<int>();
// Remaining.
List<int> totalRemaining = new List<int>();
// Product 1. Price = 20/-
// Buyed Product 1.
// 50 - 20 = 30
// After executing the below line : TotalRupees = 30
TotalRupees = TotalRupees - 20;
totalOfCosume.Add(20);
totalRemaining.Add(30);
// Product 2. Price = 15/-
// Buyed Product 2.
// 30 - 15 = 15.
// After executing the below line : TotalRupees = 15.
TotalRupees = TotalRupees - 15;
totalOfCosume.Add(15);
totalRemaining.Add(15);
// Product 3. Price = 9/-
// Buyed Product 3.
// 15 - 9 = 6.
//// After executing the below line : TotalRupees = 6.
TotalRupees = TotalRupees - 9;
totalOfCosume.Add(9);
totalRemaining.Add(6);
// Product 4. Price = 6/-
// Buyed Product 3.
// 6 - 6 = 0.
//// After executing the below line : TotalRupees = 0.
TotalRupees = TotalRupees - 6;
totalOfCosume.Add(6);
totalRemaining.Add(0);
Console.WriteLine("Total Cosume :");
foreach (var item in totalOfCosume)
{
Sum_Of_totalConsume = Sum_Of_totalConsume + item;
Console.WriteLine(item);
}
Console.WriteLine("_____");
Console.WriteLine(Sum_Of_totalConsume);
Console.WriteLine();
Console.WriteLine("Total Of Remaining :");
foreach (var item in totalRemaining)
{
Sum_Of_totalRemaining = Sum_Of_totalRemaining + item;
Console.WriteLine(item);
}
Console.WriteLine("_____");
Console.WriteLine(Sum_Of_totalRemaining);
}
}
}
输出:
答案 0 :(得分:0)
因为这是愚蠢的数学,它们并不意味着相等。
如果您要处理此问题,并从<?php
$servername = "localhost";
$username = "root";
$password = "aaa";
$dbname = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, city, country FROM order_product";
$result = $conn->query($sql);
$rows=array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$rows[]=$row;
}
} else {
echo "0 results";
}
echo json_encode($rows);
$conn->close();
?>
中取1,直到您再也没有了
TotalRupees
Total Consume: 50
希望这有帮助吗?