}
printf(\请输入变量a和b的值:\ scanf(\ *t=*p ; *p=*q ; *q=*t ;
printf(\交换后a和b的值:a=%d b=%d\\n\
-----------------------------------29 30.
编程打印200~300之间所有素数。要求判断一个数是否是素数用函数实现,打印结果请在主函数实现。判断一个数是否是素数函数原型为: int fun(int m); 参数说明:
参 数:m是要进行判断的数;
返回值:若此数是素数,则返回值为1;否则返回值为0 **输入提示信息: 无 **输入数据格式要求: 无 **输出数据格式要求: \注:不允许使用goto语句 答案:
#include
int a;
for (a = 200;a <= 300;a++) {
if (fum(a))
printf(\ else continue; } }
int fum(int m) {
int i;
for (i = 2;i < m;i++) {
if(m%i == 0) return 0; else continue; } return 1;
}
------------------------------30 31.
输入某班学生某门课的成绩(最多不超过40人),当输入为负值时,表示输入结束, 用函数编程统计成绩高于平均分的学生人数。
要求按如下原型编写统计成绩在全班平均分及平均分之上的学生人数 int GetAboveAver(int score[], int n); **输入要求:\**输出要求:
\\
\答案:
#include
int GetAboveAver(int score[], int n); int main() { }
int GetAboveAver(int score[], int n) {
d = sum / i;
printf(\for (c = 0;c < i; c++) {
if (score[c] > d) int sum = 0, c; int d, e = 0;
for (c = 0;c < i; c++) { }
sum = sum + score[c]; for (i; i <= 40; i++) { }
printf(\GetAboveAver(a, i);
int b = 0; scanf(\if (b >= 0)
a[i] = b; break; else
}
}
e++; continue;
else
printf(\return 0;
-----------------------------30 31. /*
编程实现简单的计算器功能,要求用户按如下格式从键盘输入算式: 操作数1 运算符op 操作数2
计算并输出表达式的值,其中算术运算符包括:加(+)、减(-)、乘(*)、除(/)、^(次幂)。 要求使其能进行浮点数的算术运算,同时允许使用字符*、x与X作为乘号,并且允许输入的算术表达式中的操作数和运算符之间可以加入任意多个空格符。
**输入格式要求:\提示信息:\
**输出格式要求:\+ %f = %f \\n\- %f = %f \\n\* %f = %f \\n\/ %f = %f \\n\by zero!\\n\ 程序运行示例1如下:
Please enter the expression: 2.0 + 4.0 2.000000 + 4.000000 = 6.000000 程序运行示例2如下:
Please enter the expression: 2.0 - 4.0 2.000000 - 4.000000 = -2.000000 程序运行示例3如下:
Please enter the expression: 2.0 * 4.0 2.000000 * 4.000000 = 8.000000 程序运行示例4如下:
Please enter the expression: 2.0 x 4.0 2.000000 * 4.000000 = 8.000000 程序运行示例5如下:
Please enter the expression: 2.0 X 4.0 2.000000 * 4.000000 = 8.000000 程序运行示例6如下:
Please enter the expression: 2.0 / 4.0 2.000000 / 4.000000 = 0.5000000 程序运行示例7如下:
Please enter the expression: 2.0 / 0 Division by zero! 程序运行示例8如下:
Please enter the expression:2.0 ^5.0 2.000000 ^ 5.000000 = 32.000000 程序运行示例9如下:
Please enter the expression: 2.0 \\ 4.0
Invalid operator! */
#include
-----------------------------31 32.
float a, b; char c;
printf(\); scanf(\,&a, &c, &b); if (c == '+') { }
elseif (c == '*' || c == 'x' || c == 'X')
printf(\, a, b, a*b); printf(\,a, b,pow(a,b)); printf(\); elseif (c == '^') else
if (b != 0)
printf(\, a, b, a / b); printf(\); else
printf(\, a, b, a + b); printf(\,a, b, a - b); elseif (c == '-') elseif (c == '/')
下面程序的功能是计算两个正整数的最小公倍数,请改正其中的错误。 #include
intMinCommonMultiple(inta, intb)
main() {
inta, b, x;
printf(\ scanf(\
x=MinCommonMultiple(inta,intb);
printf(\ }