C 練習(三)

來源:互聯網
上載者:User
//產生 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));}
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.