首页 > 试题广场 >

编写一个程序,要求用户输入全球当前的人口和美国当前的人口(或

[问答题]
编写一个程序,要求用户输入全球当前的人口和美国当前的人口(或其他国家的人口),将这些信息存储在long long变量中,并让程序显示美国(或其他国家)的人口占全球人口的百分比。该程序的输出应与下面类似:
Enter the world's population: 6898758899
Enter the population of the US: 310783781
The population of the US is 4.50492% of the world population.

#include<iostream>
using namespace std;
int main()
{
 long long World;
 long long US;
 cout<<"Enter the world's population:";
 cin>>World;
 cout<<"Enter the population of the US:";
 cin>>US;
 cout<<"The population of the US is "<<(100.0*US)/World<<"% of the world population.";
 return 0;
}

发表于 2019-01-25 10:41:49 回复(0)
#include <iostream>
using namespace std;
int main(void) {
    long long a;
    long long b;
    cin >> a;
    cout << "Enter the world's population: " << a << endl;
    cin >> b;
    cout << "Enter the population of the US: " << b << endl;
     cout << "The population of the US is " << ((long double)b) * 100 / a;
    cout << "% of the world's population" << endl;
   system("pause");
    return 0;

发表于 2020-09-25 22:15:41 回复(0)