C语言的编程题

王朝知道·作者佚名  2012-07-12
窄屏简体版  字體: |||超大  
 
分類: 電腦/網絡 >> 程序設計 >> 其他編程語言
 
問題描述:

1.从键盘输入任意三个整数a,b,c,求三个数中的最大值。

2. 从键盘输入任意三个数a,b,c,按从小到大的顺序排序输出。

3. 一个特定的的弹球从100米高处自由落下,每次着地后又跳回到原高度的一半再又落下,当此弹球第10次着地那一刻算起,总共经过了多少米?

4.某车库内,存放着自行车和三轮车共213辆,已知车轮的总数是548。请算出三轮车和自行车各多少辆。

5. 在100到999之间的整数中,找出所有等于它每位数字立方和的数。

如: 153=13 + 53 + 33

6. 找出所有 a* bc=cba的整数 . 如: 3*51 = 153

參考答案:

/*************************一******************************/

#include <iostream>

using namespace std;

int main()

{

int a, b, c, max;

cout << "Enter 3 number: ";

cin >> a >> b >> c;

max = (a > b ? (a > c ? a : c) : (b > c ? b : c));

cout << "The biggest number is: " << max << endl;

}

Enter 3 number: 3 1 8

The biggest number is: 8

Press any key to continue ...

/*************************二******************************/

#include <iostream>

using namespace std;

int main()

{

int num[3];

cout << "Enter 3 number: ";

cin >> num[0] >> num[1] >> num[2];

for(int i = 3; i > 0; --i)

{

for(int j = 1, temp = 0; j < i; ++j)

{

if(num[j] < num[j-1])

{

temp = num[j];

num[j] = num[j-1];

num[j-1] = temp;

}

}

}

cout << "Print in ascending order: " << num[0] << ' ' << num[1] << ' ' << num[2] << endl;

}

Enter 3 number: 5 4 3

Print in ascending order: 3 4 5

Press any key to continue ...

/*************************三******************************/

#include <iostream>

using namespace std;

double sum(double ht, int n)

{

return n > 0 ? 2*ht + sum(ht/2,n-1) : 0;

}

int main()

{

cout.setf(ios_base::fixed, ios_base::floatfield);

cout.precision(10);

// 这是向上抛100米落地10次的总距离, 所以要减去100

cout << sum(100, 10) - 100 << endl;

}

299.***********

Press any key to continue ...

/*************************四******************************/

// 这个问题貌似没必要用编程来解决吧...

// {x + y = 213

// {2x + 3y = 548

//

// { x = 91;// 自行车有那么多

// { y = 122; // 三轮车...

#include <iostream>

using namespace std;

int main()

{

int x = 0, y = 0;

bool flag = false;

for(int i = 0; i < 213; ++i)

{

for(int j = 0; j < 213; ++j)

{

if(i + j == 213 && 2*i + 3*j == 548)

{

x = i;

y = j;

flag = true;

break;

}

}

if(flag)

break;

}

cout << "有自行车: " << x << " 辆." << endl;

cout << "有三轮车: " << y << " 辆." << endl;

}

有自行车: 91 辆.

有三轮车: 122 辆.

Press any key to continue ...

/*************************五******************************/

#include <iostream>

using namespace std;

int cube(int n)

{

return n*n*n;

}

bool check(int n)

{

return cube(n%10) + cube(n%100/10) + cube(n/100) == n;

}

int main()

{

for(int i = 100; i <= 999; ++i)

{

if(check(i))

cout << i << endl;

}

}

153

370

371

407

Press any key to continue ...

/*************************六******************************/

#include <iostream>

using namespace std;

void check(int n)

{

if((n%10) * ((n%100/10)*10 + (n/100)) == n)

cout << n%10 << " * " << (n%100/10)*10 + (n/100) << " = " << n << endl;

}

int main()

{

for(int i = 100; i <= 999; ++i)

check(i);

}

6 * 21 = 126

3 * 51 = 153

8 * 86 = 688

Press any key to continue ...

小贴士:① 若网友所发内容与教科书相悖,请以教科书为准;② 若网友所发内容与科学常识、官方权威机构相悖,请以后者为准;③ 若网友所发内容不正确或者违背公序良俗,右下举报/纠错。
 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航