编程语言
首页 > 编程语言> > 实验五 函数程序设计

实验五 函数程序设计

作者:互联网

1、

#include "stdafx.h"
#include "math.h"
int add (int a,int b){
    int c;
    c=a+b;
    return c;
}

int minus (int a,int b){
    int c;
    c=a-b;
    return c;
}
int multip (int a,int b){
    int c;
    c=a*b;
    return c;
}
int quotient (int a,int b){
    int c;
    c=a/b;
    return c;
}
int mod (int a,int b){
    int c;
    c=a%b;
    return c;
}
int main(int argc, char* argv[])
{
    int x,y;
    scanf("%d %d",&x,&y);
    int d1,d2,d3,d4,d5;
    d1=add(x,y);
    d2=minus(x,y);
    d3=multip(x,y);
    d4=quotient(x,y);
    d5=mod(x,y);
    printf("%d\n%d\n%d\n%d\n%d\n",d1,d2,d3,d4,d5);
    return 0;
}

2、

#include "stdafx.h"
#include "math.h"
int prime(int n){
    int i,j;
    j=n;
    for(i=2;i<j;i++){
        if(n%i==0){
            return 0;
        }
        else if(n%i!=0){
            return 1;
        }
    }
            
}
 
int main(int argc, char* argv[])
{
    int a;
    scanf("%d",&a);
    prime(a);
    if (prime(a)==0)
        printf("No\n");
    else
            printf("Yes\n");
    return 0;
}

3、

#include "stdafx.h"
#include "math.h"
int max2(int x,int y){
    int z;
    z=x>y?x:y;
    return z;
}
int max4(int x,int y,int m,int n){
    int z;
    max2(x,y);
    int i;
    i=m>n?m:n;
    int j;
    j=z>i?z:i;
    return j;
}
int main(int argc, char* argv[])
{
    int x,y,m,n;
    int max;
    scanf("%d %d %d %d",&x,&y,&m,&n);
    max=max4(x,y,m,n);
    printf("max is %d",max);
    return 0;
}

4、

#include "stdafx.h"
#include "math.h"
int rec(int n){
    int y;
    if(n==0||n==1||n==2)
        return n;
    else
        return n*rec(n-1);
}
int main(int argc, char* argv[])
{
    int n,sum;
    scanf("%d",&n);
    sum=rec(n);
    printf("%d",sum);
    return 0;
}

标签:return,函数,int,max,实验,stdafx,程序设计,include,math
来源: https://www.cnblogs.com/P201821440042/p/10967893.html