#import <Foundation/Foundation.h>dom
//將函數指針的類型重定義;ide
typedef int (*PFUN)(int, int);函數
//1.最大值spa
int maxValue(int x, int y);3d
//2.最小值指針
int min(int x, int y);get
//3.和it
int sumValue(int x, int y);io
//4.差class
int mul(int x, int y);
//5.積
int am(int x, int y);
//6.商
int dealer(int x, int y);
//7.餘數
int yushu(int x, int y);
//8.最大公約數;
int scal(int x, int y);
//9.最小公倍數
int bei(int x, int y);
void sayHello();
int getValue();
void assign(int *p, int count);
typedef void (*PPP)();
typedef int (*P1)();
typedef void (*P2)(int *p, int count);
//將一個數正序輸出
void positive (int n);
//將一個數倒敘輸出
void revert(int n);
//n的階乘
int fac(int n);
typedef void (*rocky)(int n);//正序
typedef void (*wesley)(int n);//倒序
typedef int (*peter)(int n);//階乘
//求2個數的值
//p 是函數指針,做用是接受函數的地址
int number(int x, int y,PFUN p);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#import "Function.h"
//1.最大值
int maxValue(int x, int y) {
return x > y ? x : y;
}
//2.最小值
int min(int x, int y) {
return x < y ? x : y;
}
//3.和
int sumValue(int x, int y) {
return x + y;
}
//4.差
int mul(int x, int y) {
return x - y;
}
//5.積
int am(int x, int y) {
return x * y;
}
//6.商
int dealer(int x, int y){
return x / y;
}
//7.餘數
int yushu(int x, int y){
return x % y;
}
//8.最大公約數;
int scal(int x, int y) {
int c = x % y;
while (x % y != 0) {
x = y;
y = c;
c = x % y;
}
return y;
}
//9.最小公倍數
int bei(int x, int y) {
return x * y / scal(x, y);
}
void sayHello() {
printf("hello");
}
int getValue() {
return 20;
}
void assign(int *p, int count) {
for (int i = 0; i < count; i++) {
*(p + i) = arc4random() % (40 - 20 + 1) + 20;
}
}
//正序輸出
void positive (int n) {
if (n == 0) {
return;//結束
}
//1, 留一個數
int number = n % 10;//留取個位數
positive(n / 10);//找人
printf("%d", number);
}
//倒序輸出
void revert(int n) {
if (n == 0) {
return;
}
int number = n % 10;
printf("%d", number);
revert(n / 10);
}
//n的階乘
int fac(int n) {
if (n == 0 || n == 1) {
return 1;
}
return n * fac(n - 1);
}
//求2個數的值
int number(int x, int y, PFUN p) {
//p = maxvalue;
return p(x, y);
}