四道简单的c语言题,请大家帮帮忙了

1、对一批货物征收税收。价格在1万元以上的货物征税5%,在5000元以上,1万元以下的货物征税3%,5000元以下的货物征税2%,1000元以下的货物免税。编一程序,读入货物价格,计算并输出税金。
2、输入一个三位的数,判断该数是否为水仙花数,是则输出“flower”。(水仙花数:若三位数abc,a^3+b^3+c^3=abc ,则称该数为水仙花数)
3、输入实数x(已知0<=x<=10),计算y并输出。
2x2+3x+5 x<3
y= (x-3)2 3<=x<6
x>=6
用两种方法编程:
(1) 用IF语句编程;
(2) 用CASE语句编程
输入实数x(已知0<=x<=10),计算y并输出。
2x2+3x+5 x<3
y= (x-3)2 3<=x<6
x>=6
用两种方法编程:
(1) 用IF语句编程;
(2) 用CASE语句编程
4、输出三个整数,a、b、c中最大的数,用两种方式。
(1)if
(2)条件
第3道题粘了2遍。。请大家帮帮忙

#include "stdio.h"
int main()
{
/**************************第一题*******************************/
int nPrice = 0;
int nTax = 0;
printf("请输入货物价格:");
scanf("%d",&nPrice);
if (nPrice>=10000)
nTax = nPrice * 0.05;
else if(nPrice>=5000)
nTax = nPrice * 0.03;
else if(nPrice>=1000)
nTax = nPrice * 0.02;
else nTax =0;
printf("应缴税金为:%d\n",nTax);
return 0;
}
int main()
{
/**************************第二题******************************/
int nNum=0;
int a,b,c;
while(1)
{
printf("请输入一个三位数:");
scanf("%d",&nNum);
if (nNum==0)//输入0时退出
break;
else if (nNum>999 || nNum<100)
{
printf("输入的不是三位数!请重新输入\n");
printf("请输入一个三位数:");
scanf("%d",&nNum);
}

a = nNum/100;
b = (nNum%100)/10;
c = (nNum%100)%10;
if (a*a*a+b*b*b+c*c*c == nNum)
printf("flower\n");
else printf("不是水仙花数\n");
}
return 0;
}
int main()
{
/***************************第三题*********************************/
//******** x大于等于6时也不知道y等于多少,我就按y=x计算了 ************
int nX = 0;
int nY = 0;
printf("输入x的值:");
scanf("%d",&nX);
if (nX>10 || nX<0)
{
printf("x的值超出定义域,请重新输入!");
return 0;
}
/************ if 语句 **********************/
// if(nX<3)
// nY = 2*nX*nX+3*nX+5;
// else if(nX>=3 && nX<6)
// nY = (nX-3)*(nX-3);
// else nY = nX;
// return 0;

/*************** switch *************************/
switch(nX)
{
case 0:
case 1:
case 2:
nY = 2*nX*nX+3*nX+5;
break;
case 3:
case 4:
case 5:
nY = (nX-3)*(nX-3);
break;
default:
nY = nX;
break;
}
printf("y的值是%d\n",nY);
return 0;
}
int main()
{
/************************* 第四题 *****************************/
int a,b,c;
int max = 0;
printf("输入三个数:");
scanf("%d,%d,%d",&a,&b,&c);
/************* if 语句 **************************/
max =a;
if (max<b)
max =b;
if (max<c)
max =c;
printf("最大数是%d\n",max);
return 0;

/************* 条件表达式 ***************************/
// printf("最大数是%d\n",(a>b?a:b)>c?(a>b?a:b):c);
// return 0;

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-09-06
第一题:
#include <iostream>
using namespace std;

int main() {
int price;
while(cin >> price) {
if(price >= 10000)
cout << price + price*0.05 << endl;
else if(price >=5000)
cout << price + price*0.03 << endl;
else if(price >=1000)
cout << price + price*0.02 << endl;
else cout << price << endl;
}
return 0;
}

第二题:

#include <iostream>
using namespace std;

int pow(int a) {
return a*a*a;
}

int main() {
int n;
int sum;
while(cin >> n) {
sum = 0;
int temp = n;
while(temp) {
sum += pow(temp%10);
temp/=10;
}
if(sum == n)
cout << "Flower" << endl;
else
cout << "Not Flower" << endl;
}
return 0;
}

第三题:
1、
#include <iostream>
using namespace std;

int main() {
int x;
while(cin >> x) {
if(x < 3)
cout << 2*x*x+3*x+5 << endl;
else if(x >= 3 && x < 6)
cout << (x-3)*2 << endl;
else cout << x << endl; //x>6 What should be printed?
}
return 0;
}

2、

#include <iostream>
using namespace std;

int main() {
int x;
while(cin >> x) {
switch(x) {
case 0:
case 1:
case 2:
cout << 2*x*x+3*x+5 << endl;
break;
case 3:
case 4:
case 5:
cout << (x-3)*2 << endl;
break;
case 6:
case 7:
case 8:
case 9:
case 10:
cout << x << endl;
break;
default:
break;
}
}
return 0;
}

第四题:
1、
#include <iostream>
using namespace std;

int main() {
int a, b, c;
while(cin >> a >> b >> c) {
int temp;
if(a < b) {
temp = a;
a = b;
b = temp;
}
if(a < c) {
temp = a;
a = c;
c = temp;
}
if(b < c) {
temp = b;
b = c;
c = temp;
}
cout << a << endl;
}
return 0;
}

2、
没看懂条件是什么意思,就随便写了个
#include <iostream>
using namespace std;
int maxnum(int a, int b) {
return a > b ? a:b;
}
int main() {
int a, b, c;
while(cin >> a >> b >> c) {
cout << maxnum(maxnum(a,b),c) << endl;
}
return 0;
}

第三题 x>=6 y的表达式是什么?我随便写了个x
有问题再说……
相似回答