C程序设计第四版第四章答案

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

//5.输入一个小于1000的正数,先判断是否小于1000,若小于输出平方根的整数//部分,否则重新输入。

/*#include<stdio.h>
#include<math.h>
double Proot(double n)
{
double d;
if(n>1000)
{
printf("重新输入\n");
}
else
{
d=(double)sqrt(n);
}
return d;
}
int main()
{
printf("%.0f\n",Proot(9));
printf("%.0f\n",Proot(19));
printf("%.0f\n",Proot(1119));
return 0;
}*/
//6.当x<1时,y=x,当1<=x<10时,y=2x-1;当x>=10时,y=3x-11.编写程序。

/*#include<stdio.h>
double Fun(double x)
{
double y;
if(x<1)
{
y=x;
}
else if(x>=1&&x<10)
{
y=2*x-1;
}
else
{
y=3*x-11;
}
return y;
}
int main()
{
printf("%f\n",Fun(0));
printf("%f\n",Fun(8.9));
printf("%f\n",Fun(11110));
printf("%f\n",Fun(-1.5));
return 0;
}*/
//7.当x<0时,y=-1,当x=0时,y=0;当x>0时,y=1.编写程序。

/*#include<stdio.h>
double Fun(double x)
{
double y;
if(x<0)
{
y=-1;
}
else if(x==0)
{
y=0;
}
else
{
y=1;
}
return y;
}
int main()
{
printf("%f\n",Fun(0));
printf("%f\n",Fun(10));
printf("%f\n",Fun(-0.01));
return 0;
}*/
//8.成绩分等级
/*#include<stdio.h>
void Graded(float g)
{
if(g>=90&&g<=100)
{printf("A\n");}
else if(g>=80&&g<90)
{printf("B\n");}
else if(g>=70&&g<80)
{printf("C\n");}
else if(g>=60&&g<70)
{printf("D\n");}
else if(g<60)
{printf("E\n");}
else
{printf("others\n");}
}
int main()
{
Graded(98);
Graded(198);
Graded(68);
Graded(58);
return 0;
}*/
#include<stdio.h>
void Dengji(char s)
{
switch(s/5)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:printf("D\n");break;
case 12:
case 13:printf("C\n");break;
case 14:
case 15:
case 16:printf("B\n");break;
case 17:
case 18:
case 19:
case 20:printf("A\n");break;
default:printf("error\n");
}
}
int main()
{
Dengji(100);
Dengji(110);
Dengji(80);
Dengji(40);
return 0;
}
/*9.给一个不多于5位的正整数,求出它是几位数,分别输出每一位数字,按义序输出
各位数字*/
/*#include<stdio.h>
int Count(int n)
{int num;
if(n>9999)
{return num=5;}
else if(n>999)
{return num=4;}
else if(n>99)
{return num=3;}
else if(n>9)
{return num=2;}
else
{return num=1;}
}
int Printnum(int n)
{
int wan=n/10000;
int thou=(n-wan*10000)/1000;
int hund=(n-wan*10000-thou*1000)/100;
int shi=(n-wan*10000-thou*1000-hund*100)/10;
int ge=n-wan*10000-thou*1000-hund*100-shi*10;
printf("%d,%d,%d,%d,%d\n",wan,thou,hund,shi,ge);
printf("%d,%d,%d,%d,%d\n",ge,shi,hund,thou,wan);
return 0;
}
//int Orderfan(int n){
int main()
{printf("%d\n",Count(6789));
Printnum(7689);
printf("%d\n",Count(89));
Printnum(760);
return 0;
}*/
//10.分别用if和switch语句编写程序,求应发的奖金总额。

//if语句
/*#include<stdio.h>
double Summoney(double x)
{
double y;
if(0<x&&x<=100000)
{y=0.1*x;}
else if(100000<x&&x<=200000)
{y=100000*0.1+(x-100000)*0.075;}
else if(200000<x&&x<=400000)
{y=100000*(0.1+0.075)+(x-200000)*0.05;}
else if(400000<x&&x<=600000)
{y=100000*(0.1+0.075)+200000*0.05+(x-400000)*0.03;}
else if(600000<x&&x<=1000000)
{y=100000*(0.1+0.075)+200000*(0.05+0.03)+(x-600000)*0.015;}
else
{y=100000*(0.1+0.075)+200000*(0.05+0.03)+400000*0.015+(x-1000000)*0. 01;}
return y;
}
int main()
{
printf("%f\n",Summoney(99999));
printf("%f\n",Summoney(999999));
return 0;
}*/
//switch语句
#include<stdio.h>
double Summoney(int x)
{
double y,y1,y2,y4,y6,y10;
y1=100000*0.1;
y2=y1+100000*0.075;
y4=y2+200000*0.05;
y6=y4+200000*0.03;
y10=y6+400000*0.015;
int f;
f=x/100000;
if(f>10)
{f=10;}
switch(f)
{
case 0:y=0.1*x;break;
case 1:y=y1+(x-100000)*0.075;break;
case 2:
case 3:y=y2+(x-200000)*0.05;break;
case 4:
case 5:y=y4+(x-400000)*0.03;break;
case 6:
case 7:
case 8:
case 9:y=y6+(x-600000)*0.015;break;
case 10:y=y10+(x-1000000)*0.01;break;
}
return (int)y;
}
int main()
{
printf("%f\n",Summoney(999999));
printf("%f\n",Summoney(99999));
return 0;
}
//11.输入4个整数,要求按由小到大的顺序输出/*#include<stdio.h>
int *Ordernum(int *arr,int len)
{
int tmp;
for(int i=0;i<len;i++)
{for(int j=0;j<len-i-1;j++)
{
if(arr[j]>arr[j+1])
{
tmp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=tmp;
}
}
}
return arr;
}
void prinft(int *arr,int len)
{
for(int d=0;d<len;d++)
{
printf("%d\n",arr[d]);
}
}
int main()
{
//int arr[4]={4,3,2,1};
int arr[4]={78,90,788,4};
prinft(Ordernum(arr,4),4);
return 0;
}*/。

相关文档
最新文档