1.6
#include <stdio.h>
void main(){
int a,b,c,max;
scanf("%d %d %d",&a,&b,&c);
max=a;
if(max<b){
max=b;}
if(max<c){
max=c;}
printf("%d",max);
}
4.8
#include <stdio.h>
void main(){
float r,h;
printf("请输入半径和圆柱高:\n");
scanf("%f %f",&r,&h);
float c,j,q,v,v1;
c=3.14*r*2;
j=3.14*r*r;
q=4*3.14*r*r;
v=(4/3)*3.14*r*r*r;
v1=j*h;
printf("圆周长:%5.2f\n圆面积:%5.2f\n圆球表面积:%5.2f\n圆球体积:%5.2f\n圆柱体积:%5.2f\n",c,j,q,v,v1);
}
4.9
#include <stdio.h>
void main(){
float F;
printf("请输入一个华氏温度:\n");
scanf("%f",&F);
float c;
c=5*(F-32)/9;
printf("摄氏温度为:%5.2f\n",c);
}
5.4
#include <stdlib.h>
void main()
{
int a,b,c;
scanf("%d,%d,%d",&a,&b,&c);
if(a>b && a>c){
printf("最大值:%d\n",a);}
if(b>a && b>c){
printf("最大值:%d\n",b);}
if(c>a && c>b){
printf("最大值:%d\n",c);}
}
5.4
#include <stdlib.h>
void main()
{
int x,y;
scanf("%d",&x);
if(x<1){
y=1;}
if(x>=1 && x<10){
y=2*x-1;};
if(x>=10){
y=3*x-11;}
printf("y值为:%d\n",y);
}
5.6
#include <stdio.h>
void main(){
int a,b;
char c;
scanf("%d",&a);
b=a/10;
switch(b){
case 10: c='A';break;
case 9: c='A';break;
case 8: c='B';break;
case 7: c='C';break;
case 6: c='D';break;
default: c='E';
}
printf("%c\n",c);
}
5.9
#include <stdio.h>
void main(){
int a[4],i,j,temp;
for(i=0;i<4;i++){
scanf("%d",&a[i]);
}
for(i=0;i<3;i++){
for(j=i+1;j<4;j++){
if(a[i]>a[j]){
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<4;i++){
printf("%d ",a[i]);
}
}
5.7.1
#include <stdio.h>
void main(){
int a,i,j=0;
scanf("%d",&a);
if(a==0){
j=1;}
for(i=0;a>0;i++){
a=a/10;
j++;
}
printf("%d\n",j);
}
5.3.2
#include <stdio.h>
#include <math.h>
int getfigures(int n){
int count=0;
do{
count++;
n/=10;
}while(n!=0);
return count;
}
void main(){
int a;
scanf("%d",&a);
int len=getfigures(a)-1;
int power = pow(10.0,len);
for(int i=0;i<=len;i++){
printf("%d ",a/power);
a%= power;
power /= 10;
}
}
5.7.3
#include <stdio.h>
void main(){
int a,i,z;
scanf("%d",&a);
if(a==0){
z=0;printf("%d ",z);}
for(i=0;a>0;i++){
z=a%10;
printf("%d",z);
a=a/10;
}
}
5.8.1
#include <stdio.h>
void main(){
int a,b;
printf("请输入该公司的利润:");
scanf("%d",&a);
if(a<=100000){
b=a*0.1;}
else if(a>100000 && a<=200000){
b=100000*0.1+(a-100000)*0.075;}
else if(a>200000 && a<=400000){
b=100000*0.1+100000*0.075+(a-200000)*0.05;}
else if(a>400000 && a<=600000){
b=100000*0.1+100000*0.075+200000*0.05+(a-400000)*0.03;}
else if(a>600000 && a<=1000000){
b=100000*0.1+100000*0.075+200000*0.05+200000*0.03+(a-600000)*0.015;}
else{
b=100000*0.1+100000*0.075+200000*0.05+200000*0.03+400000*0.015+(a-1000000)*0.01;}
printf("应发奖金总数为:%d\n",b);
}
5.8.2
#include <stdio.h>
void main(){
int a,b;
printf("请输入该公司的利润:");
scanf("%d",&a);
switch(a/10000){
case 0: b=a*0.1;break;
case 1: b=100000*0.1+(a-100000)*0.075;break;
case 2:
case 3: b=100000*0.1+100000*0.075+(a-200000)*0.05;break;
case 4:
case 5: b=100000*0.1+100000*0.075+200000*0.05+(a-400000)*0.03;break;
case 6:
case 7:
case 8:
case 9: b=100000*0.1+100000*0.075+200000*0.05+200000*0.03+(a-600000)*0.015;break;
default: b=100000*0.1+100000*0.075+200000*0.05+200000*0.03+400000*0.015+(a-1000000)*0.01;
}
printf("应发奖金总数为:%d\n",b);
}
6.1
#include <stdio.h>
void main(){
int m,n,temp,r,p;
printf("请输入两个正整数:\n");
scanf("%d %d",&m,&n);
if(m<n){
temp=m;
m=n;
n=temp;
}
r=m%n;
p=m*n;
while(r!=0){
m=n;n=r;r=m%n;}
printf("最大公约数为:%d\n",n);
printf("最小公倍数为:%d\n",p/n);
}
6.2
#include <stdio.h>
void main(){
char c;
int letters=0,spaces=0,digits=0,others=0;
printf("请输入一串任意的字符:\n");
while((c=getchar())!='\n'){
if((c>='a' && c<='z')||(c>='A' && c<='Z')){
letters++;
}else if(c>='0'&&c<='9'){
digits++;}
else if(c==' '){
spaces++;}
else{
others++;}
}
printf("字母有%d个,数字有%d个,空格有%d个,其他有%d个",letters,digits,spaces,others);
}
6.3
#include <stdio.h>
void main(){
int a,n,j=0,sum=0;
scanf("%d %d",&a,&n);
for(int i=0;i<n;i++){
j=j*10+a;
sum+=j;
}
printf("%d\n",sum);
}
6.4
#include <stdio.h>
void main(){
int i,j,b=1,sum=0;
scanf("%d",&j);
for(i=1;i<=j;i++){
b*=i;
sum+=b;
}
printf("%d\n",sum);
}
6.5
#include <stdio.h>//循环要赋初值,最好什么都要赋初值
void main(){
double i,j,k,s1=0
【最简易c语言】c程序设计(第三版)谭浩强习题大部分答案
最新推荐文章于 2022-06-14 08:52:24 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)