美文网首页
第九章函数

第九章函数

作者: 小风xf | 来源:发表于2018-11-30 15:09 被阅读0次

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#define MAME " GIGGA"

#define ADDEWSS "101"

#define PLACE "Megapolis CA "

#define WIDTH 40

void starbar (void );

void main()

{

    starbar();

    printf("%s \n ", MAME);

    printf("%s \n ",ADDEWSS);

    printf("%s \n",PLACE);

    starbar();

system("pause");

}

void starbar (void )

{

    int count ;

    for (count = 1 ; count <= WIDTH; count++) {

        putchar('*');

    }

    putchar('\n');

}

I

各种复用

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#define MAME " GIGGA"

#define ADDEWSS "101"

#define PLACE "Megapolis CA "

#define WIDTH 40

#define SPACE ' '

//void starbar (void );

void show_n_char (char ch , int num);

void main()

{

    int spaces;

show_n_char('*',WIDTH);

show_n_char(SPACE,12);

printf("%s\n",MAME);

spaces = (WIDTH - strlen (ADDEWSS))/2;

  show_n_char(SPACE,spaces);

printf("%s \n" ,ADDEWSS);

show_n_char (SPACE,(WIDTH - strlen (PLACE))/2);

  printf("%s \n" ,PLACE);

  show_n_char('*' , WIDTH);

system("pause");

}

void starbar (void )

{

    int count ;

    for (count = 1 ; count <= WIDTH; count++) {

        putchar('*');

    }

    putchar('\n');

}

void show_n_char (char ch , int num)

{

int count ;

for (int count = 0; count <= num; count++)

{

putchar(ch);

}

}

找出最小数

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

int imin(int ,int);

void main()

{

int evi11,evi12;

printf("q quit \n");

while (scanf(" %d %d", &evi11,&evi12) == 2)

{

printf("  the lesser of %d and %d is %d .\n" , evi11,evi12,imin(evi11,evi12));

}

printf("\n");

}

int imin(int n ,int m)

{

int min;

if (n < m)

{

min = n;

}

else

min = m;

return min;

}

\

使用函数  原形

#include <stdlib.h>

int imin(int ,int);//

void main()

{

// printf("  the lesser of %d and %d is %d .\n" , 3,5,imin(3  ));

printf("  the lesser of %d and %d is %d .\n" , 3 ,5,imin(3.0,5.0));

system("pause");

}

int imin(int n ,int m)

{

int min;

if (n < m)

{

min = n;

}

else

min = m;

return min;

}

递归

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

void up_and_down(int n )

{

printf("lever %d n liocation %p \n" , n ,&n );

if(n < 4)

{

up_and_down(n+1);

}

printf("lever %d n liocation %p \n" , n ,&n );

}

void main()

{

up_and_down(1 );

system("pause");

}

使用循环和递归 计算阶乘

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

long face (int );

long rfacet (int );

void  main()

{

int num ;

printf(" this program clculates \n");

printf(" enter a valiue in the rang q ");

while (scanf ("%d",&num) == 1)

{

if (num < 0 )

{

printf(" no  ne");

}

else if (num > 12)

{

printf(" keep \n");

}

else

{

printf("loop %d facetorial = %ld \n" , num,face(num));

printf("recursion%d factorial = %ld \n ",num ,rfacet(num));

}

}

system("pause");

}

long face(int n )

{

long ans ;

for ( ans = 0; n>1; n --)

{

ans *= n;

}

return ans;

}

long rfacet(int n )

{

long ans ;

if(n > 0 )

ans = n * rfacet(n-1);

else

ans = 1;

return ans;

}

递归实现二进制运算

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

void to_binary(unsigned long);

int main()

{

unsigned long number;

printf ("enter an integer q\n ");

while (scanf("%ul",&number) == 1 )

{

to_binary(number);

putchar('\n');

}

system ( "pause");

}

void to_binary(unsigned long n)

{

int r ;

r = n %2;

if ( n >=2)

{

to_binary(n/2);

}

putchar('0' + r);

}

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

#include "stdafx.h"

int menu(void)

{

int code , status;

printf(" \n %s %s \n",STARS,STARS);

printf("1,fair arms ,2 hotel ,3 ,char ,4 the ,5 quit\n");

printf(" \n %s %s \n",STARS,STARS);

while ((status = scanf("%d", &code)) != 1 || (code < 1 || code> 5) );

{

if (status != 1 )

{

scanf("%*s");

}

printf(" to 5 ");

}

return code;

}

int  getnights (void )

{

int nights;

while (scanf("%d",&nights ) != 1)

{

scanf("%*s");

}

return nights;

}

void showprice ( double rate ,int nights)

{

int n ;

double total = 0.0;

double factor = 1.0;

for (  n = 1; n <= nights; n++, factor *= DISCOUNT)

{

total += rate * factor;

}

printf(" tje tpta; cpst woll be %0.2f\n",total);

}

#include < stdio.h>

#include "stdafx.h"

int main()

{

int nights ;

double hotel_rate;

int code;

while ((code = menu()) != QUIT)

{

switch (code)

{

case 1 :

hotel_rate = HOTEL1;

break;

case 2 :

hotel_rate = HOTEL2;

break;

case 3 :

hotel_rate = HOTEL3;

break;

case 4 :

hotel_rate = HOTEL4;

break;

default:

hotel_rate = 0.0;

printf("oooops\n");

break;

}

nights = getnights();

showprice (hotel_rate,nights);

}

printf("hello \n");

}

#include <stdio.h>

#define QUIT 5

#define  HOTEL1 80.00

#define  HOTEL2 125.00

#define  HOTEL3 155.00

#define  HOTEL4 200.00

#define  DISCOUNT 0.95

#define  STARS "*********************"

int menu(void );

int getnights (void);

void showprice (double,int);

函数的 副本 机制 

#include <stdio.h>

#include <stdlib.h>

void mikado (int );

void main()

{

int pooh = 2 ,bah = 5;

printf(" In mikado () , pooh = %d and &pooh = %p \n", pooh,&pooh);

printf(" In mikado () , bah = %d and &pooh = %p \n", bah,&bah);

mikado(pooh);

printf("hello");

system("pause");

}

void mikado (int bah)

{

int pooh = 10 ;

printf(" In mikado () , pooh = %d and &pooh = %p \n", pooh,&pooh);

printf(" In mikado () , bah = %d and &pooh = %p \n", bah,&bah);

}

指针交换两个数值

#include <stdio.h>

#include <stdlib.h>

void interchang  (int *,int *);

void main()

{

int x = 5 , y = 10 ;

printf(" x = %d y = %d ", x,y);

interchang (&x,&y);

printf("\n x = %d y = %d ", x,y);

system("pause");

}

void interchang( int *u ,int *v)

{

int temp ;

temp = *u ;

*u = *v ;

*v = temp;

//printf("\n u = %d v = %d ", u,v);

}

通过

通过指针变量 获取有关zippo的值

#include <stdio.h>

#include <stdlib.h>

#define SIZE 5

void main()

int zippo [4][2] = {{2,4},{6,8},{1,3},{5,7} };

int (*pz)[2];

pz = zippo;

printf("pz = %p  pz + 1 = %p  \n",pz,pz+1 );

printf("pz[0] = %p pz[0]+1 = %p,  \n",pz[0] ,pz[0]+1);

printf("*pz  = %p *pz +1 = %p,  \n",*pz  ,*pz +1);

printf("pz[0][0]  = %d  \n",pz[0][0] );

printf("*pz [0]  = %d  \n",*pz[0] );

  printf("pz[2][1]  = %d  \n",pz[2][1] );

  printf(" pz[2][1]  = %d  \n",  *(*(pz+2)+1) );

system("pause");

相关文章

  • 第九章 SQL聚合函数 MIN

    第九章 SQL聚合函数 MIN 返回指定列中的最小数据值的聚合函数。 大纲 参数 ALL - 可选-将聚合函数应用...

  • 第九章 Caché 函数大全 $CLASSNAME 函数

    第九章 Caché 函数大全 $CLASSNAME 函数 返回类的名称。 大纲 参数 n 可选-对类实例的对象引用...

  • Swift(三 函数 闭包)

    第九章 函数 关于函数返回值为元组的情况下,打印字段值(多返回值函数的两种方式实现:1、在函数定义时,将函数的多个...

  • [swift 进阶]读书笔记-第九章:泛型 C9P1 重载

    第九章:泛型 Generics 9.1 重载 Overloading 自由函数的重载 Overload Resol...

  • 《批判性思维》第九章(1)

    本周开始第九章的学习,演绎论证2,真值函数逻辑。 真值函数逻辑,又称为判断或语句逻辑。 第一节介绍真值表和真值函数...

  • 第九章函数

    #include #include #include #define MAME " GIGGA" #define ...

  • 第九章 SQL查询数据库(二)

    第九章 SQL查询数据库(二) 调用用户定义函数的查询 InterSystems SQL允许您在SQL查询中调用类...

  • C语言笔记(三)--- 预处理指令

    第九章 预处理命令 例如包含命令 #include宏定义命令 #define 这些命令都放在函数之外,而且一般都放...

  • 第九章 内联函数

    简介:C++中预处理器宏存在的问题,在C++中如何用内联函数解决这些问题以及使用内联函数的方针和内联函数的工作机制...

  • 第九章 函数基础

    一 没有使用函数式编程之前带来的问题 代码的组织结构不清晰,可读性差 实现重复的功能时,你只能重复编写实现功能的代...

网友评论

      本文标题:第九章函数

      本文链接:https://www.haomeiwen.com/subject/tcshcqtx.html