编写一个C++程序,要求用longlong变量储存。

编写一个C++程序,要求用户输入全球当前的人数和美国当前的人数,将这些人数储存在long long变量中,并让程序显示美国的人口占全球人口的百分比
例如: Enter the world's population: 6898758899
Enter the population of the us:310783781
the population of the US is 4.50492% os the world population.

看你的编译器是否支持 long long 型。
如果是 MS VC++ 6.0, long long 型 用 _int64 表示,输入格式 %I64d
别的编译器,按自己情况决定。

# include <stdio.h>
void main()
{
_int64 x,y; // this is long long type in MS VC++ 6.0
double zz;
printf("enter the world's population: 6898758899:\n");
scanf("%I64d", &x);
printf("enter the U.S. population: 310783781:\n");
scanf("%I64d", &y);
zz = (double) y / (double) x;
printf("%lf%%", zz*100.0); // %% will produce a single % mark
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-02-07
#include "stdio.h"

//我的VC不支持long long类型,为了调试就这样定义下
#ifdef _MSC_VER
#define Int64 __int64
#define IO64 "%I64d"
#else
#define Int64 long long
#define IO64 "%lld"
#endif

int main(int argc, char* argv[])
{
Int64 wp, up;
printf("Enter the world's population:");
scanf(IO64, &wp);
printf("Enter the population of the us:");
scanf(IO64, &up);
printf("the population of the US is %.5f os the world population.\n", up * 100.0 / wp);
return 0;
}本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网