C 练习(三)
//生成 100~200的随机数 #include <stdio.h> #include <stdlib.h> int min; int find(){ int i, y, x,max; x = rand()%101 + 100; max = x; min = x; printf("生成的随机数为:\n%d\n",x); for(i =0;i<9;i++){ y = rand()%101 + 100; printf("%d\t\n",y); if(y>max) max = y; if(y<min) min = y; } return max; } void main(){ int max = find(); printf("最大数为%d ,最小数为%d",max,min); } //静态变量求1~5的阶层 #include <stdio.h> #include <stdlib.h> int fac(int n){ static int f = 1; f *= n; return f; } void main(){ int k; for(k=1;k<=5;k++){ printf("%d! = %d\n",k,fac(k)); } } //判断为该年第几天 #include <stdio.h> int days(int year,int month,int day){ int i,count=0,monthArr[] = {31,28,31,30,31,30,31,31,90,31,30,31}; if( ((year%100)&&!(year%4)) || !(year%400) ) monthArr[1] = 29; for(i=0;i<month-1;i++){ count += monthArr[i]; } count += day; return count; } void main(){ int year,month,day; printf("请依次输入年、月、日\n"); scanf("%d,%d,%d",&year,&month,&day); printf("%d年%d月%d日为该年的第%d天",year,month,day,days(year,month,day)); }
生命只有一次。