Advertisement
kk258966

11/28 進階程式設計 練習三

Nov 28th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(void)
  4. {
  5.     int no[100],i,count;
  6.     int *ptr=no;
  7.     srand(time(NULL));
  8.    
  9.     ptr= &no[1];
  10.     for(i=1;i<=10;i++) //產生10個亂數,丟進陣列
  11.     {
  12.        *ptr=rand()%100;
  13.        ptr++;                          
  14.     }
  15.     ptr=&no[1];
  16.        for(i=1;i<=10;i++) //利用指標走訪陣列,列印出來。
  17.     {
  18.        printf("值:(%d),位址:(%p)\n",*ptr,ptr);
  19.        ptr++;                          
  20.     }
  21.    
  22.     int max=0,min=100;
  23.     int *ptr_max=&max,*ptr_min=&min;
  24.    
  25.     for(i=1;i<=10;i++)
  26.     {
  27.        ptr =&no[i];
  28.        if(*ptr<*ptr_min)
  29.        *ptr_min=*ptr;
  30.                      
  31.     }
  32.    
  33.     printf("最小值為:%d\n",*ptr_min);
  34.    
  35.  
  36.  
  37.     system("pause");
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement