6.6实验五
Posted p201821430045
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了6.6实验五相关的知识,希望对你有一定的参考价值。
1.
#include <stdio.h> int main() float add(float x,float y); float minus(float x,float y); float multiply(float x,float y); float division(float x,float y);
float x,y,a,b,c,d; printf("Please enter x and y:"); scanf("%f,%f",&x,&y); a=add(x,y); printf("sum is %f\\n",a); b=minus(x,y); printf("minus is %f\\n",b); c=multiply(x,y); printf("multiply is %f\\n",c); d=division(x,y); printf("division is %f\\n",d); return 0;
float add(float x,float y) float z; z=x+y; return(z); float minus(float x,float y) float p; p=x-y; return (p); float multiply(float x,float y) float q; q=x*y; return(q); float division(float x,float y) float s; s=x/y; return(s);
2.
#include<stdio.h> int main() int prime(int); int n; printf("input an integer:"); scanf("%d",&n); if (prime(n)) printf("YES\\n"); else printf("NO\\n"); return 0;
int prime(int n) int flag=1; int i; for (i=2;i<n/2 && flag==1;i++) if(n%i==0) flag=0; return(flag);
3.
#include <stdio.h> int main() int max4(int a,int b,int c,int d); int a,b,c,d,max; printf("Please enter 4 intergrt numbers:\\n"); scanf("%d %d %d %d",&a,&b,&c,&d); max=max4(a,b,c,d); printf("max=%d\\n",max); return 0; int max4(int a,int b,int c,int d) int max2(int a,int b); int m; m=max2(max2(max2(a,b),c),d); return(m); int max2(int a,int b) return(a>=b?a:b);
4.
#include <stdio.h> int main() int fac(int n); int n; int y; printf("input an interger number:"); scanf("%d",&n); y=fac(n); printf("%d != %d\\n",n,y); return 0;
int fac(int n) int f; if(n<0) printf("n<0,data error!"); else if(n==0 || n==1) f=1; else f=fac(n-1)*n; return(f);
以上是关于6.6实验五的主要内容,如果未能解决你的问题,请参考以下文章
2018-2019-2 20175306实验五《网络编程与安全》实验报告