第十三堂课后作业

来源:互联网 发布:快速优化软件 编辑:程序博客网 时间:2024/04/29 21:34

作业1:
通过输入两个加数,给学生出一道加法运算题。如果输入答案正确,则显示“Y”;否则显示“N”。
要求:程序循环执行n次,用函数实现判断对错和输出结果
我的程序:

#include<stdio.h>double p(double a,double b){double x;x=a+b;return (x);}void main(){double c,d,e;for(; ;){printf ("put two number\n");scanf("%lf%lf",&c,&d);printf("%lf+%lf=\n",c,d);scanf("%lf",&e);if(e==p(c,d))    printf("y\n");elseprintf("n\n");}}

运行结果: