#include<stdio.h>#include<string.h>intmain(){voidprint_star();voidprint_message();print_star();print_message();print_star();return0;}voidprint_star(){printf("**********\n");}voidprint_message(){printf("how do you do!\n");}
7.2输入两个整数,要求输出其中值较大者。
intmax(int x,int y){int z;
z=x>y?x:y;return(z);}#include<stdio.h>intmain(){intmax(int x,int y);int a,b,c;printf("please enter two inteter numbers:");scanf("%d,%d",&a,&b);
c=max(a,b);printf("max is %d\n",c);return0;}
#include<stdio.h>intmain(){floatadd(float x,float y);float a,b,c;printf("please enter a and b:");scanf("%f,%f",&a,&b);
c=add(a,b);printf("sum is %f\n",c);return0;}floatadd(float x,float y){float z;
z=x+y;return(z);}
#include<stdio.h>intmain(){voidhanoi(int n,char one,char two,char three);int m;printf("input the number of diskes:");scanf("%d",&m);printf("the step to move %d diskes:\n",m);hanoi(m,'A','B','C');}voidhanoi(int n,char one ,char two,char three){voidmove(char x,char y);if(n==1)move(one,three);else{hanoi(n-1,one,three,two);move(one,three);hanoi(n-1,two,one,three);}}voidmove(char x,char y){printf("%c-->%c\n",x,y);}
7.9输入10个数,要求输出其中最大的元素和改数是第几个数。
#include<stdio.h>intmain(){intmax(int x,int y);int a[10],m,n,i;printf("enter 10 integer numbers:");for(i=0;i<10;i++)scanf("%d",&a[i]);printf("\n");for(i=1,m=a[0],n=0;i<10;i++){if(max(m,a[i])>m){m=max(m,a[i]);
n=i;}}printf("the lagest number is %d\nit is the %dth number.\n",m,n+1);}intmax(int x,int y){return(x>y?x:y);}
7.10 有一个一维数组score,内放10个学生成绩,求平均成绩。
#include<stdio.h>intmain(){floataverage(float array[10]);float score[10],aver;int i;printf("input 10 score:\n");for(i=0;i<10;i++)scanf("%f",&score[i]);printf("\n");
aver=average(score);printf("average score is %5.2f\n",aver);return0;}floataverage(float array[10]){int i;float aver ,sum=array[0];for(i=1;i<10;i++)
sum=sum+array[i];
aver=sum/10;return(aver);}
#include<stdio.h>intmain(){floataverage(float array[],int n);float score1[5]={98.5,97,91.5,60,55};float score2[10]={67.5,89.5,99,69.5,77,89.5,76.5,54,60,99.5};printf("the average of class A is %6.2f\n",average(score1,5));printf("the average of class B is %6.2f\n",average(score2,10));return0;}floataverage(float array[],int n){int i;float aver ,sum=array[0];for(i=1;i<n;i++)
sum=sum+array[i];
aver=sum/n;return(aver);}
#include<stdio.h>intmain(){intmax_value(int array[][4]);int a[3][4]={{1,3,5,7},{2,4,6,8},{15,17,34,12}};printf("max value is %d\n",max_value(a));return0;}intmax_value(int array[][4]){int i,j,max;
max=array[0][0];for(i=0;i<3;i++)for(j=0;j<4;j++)if(array[i][j]>max)max=array[i][j];return(max);}
#include<stdio.h>intmain(){intfac(int n);int i;for(i=1;i<=5;i++)printf("%d!=%d\n",i,fac(i));return0;}intfac(int n){staticint f =1;
f=f*n;return(f);}
7.18 调用函数,求3个整数中的大者。
#include<stdio.h>intmain(){intmax();externint A,B,C;printf("please enter three integer numbers:");scanf("%d%d%d",&A,&B,&C);printf("max is %d\n",max());return0;}int A,B,C;intmax(){int m;
m=A>B?A:B;if(C>m)m=C;return(m);}
7.19给定b的值,输入a和吗,求a*b和a的m次方的值。
#include<stdio.h>int A;intmain(){intpower(int);int b=3,c,d,m;printf("enter the number a and its power m:\n");scanf("%d,%d",&A,&m);
c=A*b;printf("%d*%d=%d\n",A,b,c);
d=power(m);printf("%d**%d=%d\n",A,m,d);return0;}extern A;intpower(int n){int i,y=1;for(i=1;i<=n;i++)
y*=A;return(y);}