admin 管理员组

文章数量: 1086019


2024年3月26日发(作者:姓陈专属英文名)

实验6-1

课后练习:

1. 选择题

(1)B (2)C(3)A(4)D(5)C (6)C (7)D

2.阅读程序,写出运行结果

30

20

10

3.阅读程序,写出运行结果

20

10

4. 阅读程序,写出运行结果

1 2 3

5.阅读程序,写出运行结果

7 8 9

6.阅读程序,写出运行结果

9

7.阅读程序,写出运行结果

#include

int digit(int n,int k);

int main()

{ int n,k;

printf("Enter n,k: ");

scanf("%d %d",&n,&k);

printf("nThe result is:%dn",digit(n,k));

return 0;

}

int digit(int n,int k)

{ int d;

while(k>0)

{ d=n%10;

n=n/10;

k--;

}

return d;

}

8.程序填空

#include

double max(double a,double b);

int main()

{ double x,y;

prinf("please input two double numbers:");

scanf("%lf %lf"),&x,&y;

printf("%.2fn",max(x,y));

return 0;

}

double max(double a,double b)

{

return (a>b?a:b);

}

9.

原版

#include

int check(int n,int d);

int main()

{ int n,d;

printf("Enter n,d: ");

scanf("%d %d",&n,&d);

if(check(n,d)==1)

printf("The digit %d is in data %d",d,n);

else

printf("The digit %d is not in data %d",d,n);

return 0;

}

int check(int n,int d)

{ int temp;

while(n>0)

{ temp=n%10;

if(temp==d)return 1;

n=n/10;

}

return 0;

}

改进版

#include

int check(int n,int d);

int main()

{ int n,d,position;

printf("Enter n,d: ");

scanf("%d %d",&n,&d);

position=check(n,d);


本文标签: 阅读程序 作者 程序 运行 结果