华为面试题
假设一年365天,光速为350万千米/秒,写一个函数打印光一年走过多少米? 又一个拿数组当数字的[em26] 又是华为的~~~[em07] [code]//usage:distance of a lightyear
//author:zhponly
//date:20080414
//edit:none
//edition:none
//vc++6.0+windows xp
#include<iostream>
void PrintDistanceOfL(void);
using namespace std;
int main(void)
{
PrintDistanceOfL();
return 0;
}
void PrintDistanceOfL(void)
{
long unsigned int Result; //result
unsigned int DayOfYear=365;
unsigned int SecondsOfDay=864; //secondsofday=864*1 00
unsigned int SpeedOfL=35; //speedofl=35*1 0000 0000m
Result=DayOfYear*SecondsOfDay*SpeedOfL;
cout<<Result; //less of 00 0000 0000
for(int i=0;i<10;i++)
cout<<0; // 00 0000 0000
cout<<endl; //change line
}[/code] 貌似光速不是一秒35吧..............[em30] 倒不是特别特别难 就是题目太变态了 。。。
这样的题我就做不出来。。 ANSWER:可以只计算365*24*36*35保存为字符串后面在接几个0 才发现 光速变了 [quote]原帖由 [i]爱因[/i] 于 2008-4-16 19:14 发表 [url=http://bbs.ghtt.net/redirect.php?goto=findpost&pid=1191733&ptid=101554][img]http://bbs.ghtt.net/images/common/back.gif[/img][/url]
才发现 光速变了 [/quot
哈哈,什么都会变的,不要跟不上时代。 华为总是这么bt
页:
[1]