c++练习题

悬赏40分http://zhidao.baidu.com/question/246004511.html1.便写程序用ifelse分支结构语句,求a,b,c三个数中最大的... 悬赏40分 http://zhidao.baidu.com/question/246004511.html

1.便写程序用if else分支结构语句,求a,b,c三个数中最大的

数并将其放在变量max中。
2.某篮球专卖店篮球单价145元/个。批发规则为:一次购买10

个以内不打折;一次购买20个以内打9折;一次购买40个以内8

折;一次购买50个以内打7折;一次购买超50个(含50个)一律

按65元/个计算。写程序实现当输入用户购买篮球的个数时,立

即输出其付款金额。用swith语句实现分支结构,试写源程序。
3.编写程序,用循环语句求100以内的奇数之和。1+3+5+……。
4.编写程序,用循环语句求n!的值
5.编写程序,用循环语句求不规则区域面积。求在[0,PI]内正

弦曲线y=sinx与 x轴围成区域的面积。
展开
 我来答
kickchow
推荐于2016-07-26 · TA获得超过421个赞
知道小有建树答主
回答量:272
采纳率:0%
帮助的人:236万
展开全部
1.
if (a > b && a > c)
max = a;
else if (b > a && b > c)
max = b;
else
max = c;
2.
while ( cin >> amount){
amt = amount / 10;
switch (amt){
case 0: pay = amount * PRICE; cout << pay << endl; break;
case 1: pay = amount * PRICE * 0.9; cout << pay << endl; break;
case 2:
case 3: pay = amount * PRICE * 0.8; cout << pay << endl; break;
case 4: pay = amount * PRICE * 0.7; cout << pay << endl; break;
default: pay = amount * other; cout << pay << endl; break;
}
}
3.
int sum = 0;
for (int i = 1; i < 100; i = i + 2)
{
sum += i;
}
4.
double factor = 1;
for (int i = 0; i < n; i++)
{
if (i == 0 || i == 1)
factor = 1;
else
factor *= i
}
5.
这个貌似不会、、追问第2题 能完整点吗?
回答#include <iostream>
const int PRICE = 100;
const int other = 80;
int main()
{
using std::cout;
using std::cin;
using std::endl;
int amount, amt;
int pay;
cout << "Enter your amount: ";
while (cin >> amount)
{
amt = amount / 10;
switch (amt)
{
case 0:
pay = amount * PRICE;
cout << "total pay: " << pay << endl;
break;
case 1:
pay = amount * PRICE * 0.9;
cout << "total pay: " << pay << endl;
break;
case 2:
case 3:
pay = amount * PRICE * 0.8;
cout << "total pay: " << pay << endl;
break;
case 4:
pay = amount * PRICE * 0.7;
cout << "total pay: " << pay << endl;
break;

default:
pay = amount * other;
cout << "total pay: " << pay << endl;
break;
}
}
return 0;
}
匿名用户
2011-04-01
展开全部
,开阔思维也锻炼自己的代码能力。可以去北大的在线Judge系统提交程序并且知道是否正确。很有意思也非常有意义。
百度搜索POJ,第一项就是北大ACM Judge Online的官网。都是很锻炼编程能力的英文题目。

这是几个经典的题目,来自于我专业的实验课。

约瑟夫环
n number of persons form a circle. The first person starts to count 1. The next person count 2 and so on. The person who counts t will leave the circle. This game will end if no person remains in the circle.

Write a simple program to output the sequence of persons leaving the circle. The input data contains two lines. The first line stores the value of t and the second line stores the value of n.

Example:
Input:
2
5

Output:
2 4 1 5 3

大数乘法
Write a simple calculator program which can do the multiplication operation for any two non-negative integer numbers. The program reads the integers in stdin. The input has two lines and each line contains an non-negative integer. Finally, the result of multiplication will be printed on the screen.

Example:
Input:
9545217425415636
5548

Output:
52956866276205948528
另外,团IDC网上有许多产品团购,便宜有口碑
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
sr00en
2011-03-31 · TA获得超过847个赞
知道答主
回答量:642
采纳率:0%
帮助的人:0
展开全部
,开阔思维也锻炼自己的代码能力。可以去北大的在线Judge系统提交程序并且知道是否正确。很有意思也非常有意义。
百度搜索POJ,第一项就是北大ACM Judge Online的官网。都是很锻炼编程能力的英文题目。

这是几个经典的题目,来自于我专业的实验课。

约瑟夫环
n number of persons form a circle. The first person starts to count 1. The next person count 2 and so on. The person who counts t will leave the circle. This game will end if no person remains in the circle.

Write a simple program to output the sequence of persons leaving the circle. The input data contains two lines. The first line stores the value of t and the second line stores the value of n.

Example:
Input:
2
5

Output:
2 4 1 5 3

大数乘法
Write a simple calculator program which can do the multiplication operation for any two non-negative integer numbers. The program reads the integers in stdin. The input has two lines and each line contains an non-negative integer. Finally, the result of multiplication will be printed on the screen.

Example:
Input:
9545217425415636
5548

Output:
52956866276205948528
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
划过天空kaka
2011-03-31 · TA获得超过107个赞
知道答主
回答量:70
采纳率:0%
帮助的人:40.2万
展开全部
问题二补充:在不能确定用户输入数据的情况下验证用户输入

判断输入都是数值

public static bool IsNum(string Num)
{
const string regPattern = @"^[0-9]*[1-9][0-9]*$"; //正整数
return Regex.IsMatch(Num, regPattern);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式