{ float x,y,z,temp;
printf(\ scanf(\,&z); if (x>y) {temp=x; x=y; y=temp; }
if (x>z) {temp=x; x=z; z=temp; }
if (y>z) {temp=y; y=z; z=temp; }
printf(\,x); getch(); }
4.5.4:某大型电器公司在国庆节期间推出以下促销优惠活动:当天所购商品价值在20000元以上(包括20000元)的顾客,将享受7.5折优惠;当天所购商品价值在15000元以上(包括15000元)的顾客,将享受8折优惠;当天所购商品价值在10000元以上(包括10000元)的顾客,将享受8.5折优惠;当天所购商品价值在5000元以上(包括5000元)的顾客,将享受9折优惠;其他顾客享受9.5折优惠。编写实现该优惠活动的程序。
/* HELLO.C -- Hello, world */
#include \#include \
main() {
float x; float y;
printf(\ scanf(\ if(x>=20000) {y=x*0.75;} else if (x>=15000) {y=x*0.8;}
else if (x>=10000)
{y=x*0.85;} else if (x>=5000) {y=x*0.9;} else
{y=x*0.95;} printf(\ getch(); }
4.5.5:写出实现以下函数的对应程序,要求:输入x,计算并输出函数y的值(保留两位小数)。 X+10,(x<0) Y= 20 , (x=0) 30x, (x>0)
/* HELLO.C -- Hello, world */
#include \#include \
main() {
float x; float y;
printf(\ scanf(\ if(x>0)
{y=x*30;} else if(x<0)
{y=x+10;} else {y=20;} printf(\ getch(); }
4.5.10:输入一个4位正整数,求出对应位的数字并输出,最后将千位和十位互换,百位和个位互换并输出(例:输入1256,最后输出5612),其他输入提示错误。 #include \
void main() {
int x,y,a,b,c,d;
printf(\scanf(\
if(x>=1000&&x<10000) {
a=x;printf(\
b=(x/10);printf(\ c=(x/100);printf(\ d=(x/1000);printf(\
y=b*1000+a*100+d*10+c;printf(\} else {
printf(\ }
getch(); }
5.5.3.2:编一程序输出如下图形: 1
121 12321 1234321 123454321 12345654321
/* HELLO.C -- Hello, world */
#include \#include \
main() { int i,j;
for(i=1;i<=6;i++) { for(j=1;j<=6-i;j++) printf(\
for(j=1;j<=i;j++) printf(\ for(j=i-1;j>=1;j--)
printf(\ printf(\ }
getch(); }
5.6.3:设计程序输出Fibonacci数列的前50个数,其开始两个数是1、1,从第三
个数开始,每个数等于前两个数之和。例如,1、1、2、3、5、8、13、…。
/* HELLO.C -- Hello, world */
#include \#include \
int main() {
long x[16] = {0,1}; int i;
for(i=2;i<16;i++) x[i] = x[i-1]+x[i-2]; for(i=1;i<16;i++)
printf(\getch (); }
5.6.7:用循环程序输出以下图案。 * *** ***** ******* ***** *** *
/* HELLO.C -- Hello, world */
#include \#include \
void main() {int a,b,c;
for(a=1;a<=4;a++) {
for(b=1;b<=4-a;b++) printf(\
for(c=2;c<=2*a;c++) printf(\printf(\}
for(a=0;a<=2;a++) {
for(b=0;b<=a;b++) printf(\

