ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

函数练习题17

2019-12-02 20:52:38  阅读:225  来源: 互联网

标签:练习题 pause return 函数 17 int void printf fun


#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");
}

标签:练习题,pause,return,函数,17,int,void,printf,fun
来源: https://www.cnblogs.com/yuzhenghan/p/11973199.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有