函数练习题17

#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>//函数练习题
#include<stdlib.h>
int a = 5;
void fun(int b){
 static int a = 10;
 a += b++;
 printf("%d\n", a);
}
void main(){
 int c = 20;
 fun(c);
 a += ++c;
 printf("%d\n", a);
 system("pause");
 return 0;
}
void fun(char *c, int d){
 *c = *c + 1;
 d = d + 1;
 printf("%c,%c\n", *c, d);
}
void main(){
 char a = 'A', b = 'a';
 fun(&b, a);
 printf("%c,%c\n", a, b);
 system("pause");
 return 0;
}
char fun(char x, char y){
 if (x < y)
  return x;
 else
  return y;
}
void main(){
 int a = '9';
 int b = '8';
 int c = '7';
 printf("%c\n", fun(fun(a, b), fun(b, c)));
 system("pause");
}
void fun(int *s){
 static int j = 0;
 do{
  s[j] += s[j + 1];
 } while (++j < 2);
}
void main(){
 int k, a[10] = { 0, 1, 2, 3, 4 };
 for (k = 1; k < 3; k++)
  fun(a);
 for (k = 0; k < 5; k++)
  printf("%d", a[k]);
 system("pause");
}
int func(int x){
 int p;
 if (x == 0 || x == 1)
  return 3;
 p = x + func(x - 3);
 return p;
}
void main(){
 int num;
 num=func(12);
 printf("num=%d",num);
 system("pause");
}
int fa(int x){
 return x*x;
}
int fb(int x){
 return x*x*x;
}
int f(int(*f1)(), int(*f2)(),int x){
 return f2(x) - f1(x);
}
void main(){
 int i;
 i = f(fa, fb, 2);
 printf("%d\n", i);
 system("pause");
 return 0;
}
int fun(int n){//调用fun函数实现m=1-2+3-4+5-6
 int m = 0;
 int f = 1;
 int i;
 for (i = 1; i <= n; i++){
  m += i*f;
  f = (-1)*f;
 }
 return m;
}
void main(){
 printf("m=%d\n", fun(10));
 system("pause");
}
int  main(){
 int i;
 int n;
 int j;
 printf("input n:");
 scanf("%d",&n);
 for (i = 1; i <= n; i++){
  for (j = 1; j <= 2 * i- 1; j++){
   printf("*");
  }
  printf("\n");
 }
 system("pause");
 return 0;
}

#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
char *day_name(int n){//指针函数
 static char *name[] = { "one day", "Monday", "Tuesday", "Wednesday", "Thursday",
  "Friday", "Saturday", "Sunday" };
 return((n<1 || n>7) ? name[0] : name[n]);
}
void main(){
 int i;
 printf("input Day no : \n");
 scanf("%d", &i);
 if (i<0 || i>7){
  exit(1);
 }
 printf("Day no:%2d-->%s\n", i, day_name(i));
 system("pause");
}

define  _CRT_SECURE_NO_WARNINGS
#include<stdlib.h>//指针函数求两个数之间的大小
#include<stdio.h>
int *zuidazhi(int i, int j){
 if (i > j){
  return (&i);
 }
 else{
  return (&j);
 }
}
void main(){
 int y;
 int *p;
 int x;
 printf("input y and x:");
 scanf("%d%d", &x,&y);
 p = zuidazhi(x, y);
 printf("zuidazhi=%d\n",*p);
 system("pause");
}
int minp(int *x, int *y){
 int *q;
 q = *x < *y ? x : y;
 return(q);
}
int main(){
 int a, b, *p;
 printf("input a and b");
 scanf("%d%d", &a, &b);
 p = minp(&a, &b);
 printf("\nminp=%d", *p);
 system("pause");
 return 0;
}

#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>//通过函数指针求两个是之间最大值
int zuidazhi(int x, int y){
 return (x > y ? x : y);
}
void main(){
 int zuidazhi(int ,int);
 int(*p)(int ,int);
 int a, b, c;
 p = zuidazhi;
 printf("Please input two integer numbers:");
 scanf("%d %d", &a, &b);
 c = (*p)(a, b);
 printf("c=%d\n", c);
 system("pause");
}

猜你喜欢

转载自www.cnblogs.com/yuzhenghan/p/11973199.html