Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(void)
- {
- int no[100],i,count;
- int *ptr=no;
- srand(time(NULL));
- ptr= &no[1];
- for(i=1;i<=10;i++) //產生10個亂數,丟進陣列
- {
- *ptr=rand()%100;
- ptr++;
- }
- ptr=&no[1];
- for(i=1;i<=10;i++) //利用指標走訪陣列,列印出來。
- {
- printf("值:(%d),位址:(%p)\n",*ptr,ptr);
- ptr++;
- }
- int max=0,min=100;
- int *ptr_max=&max,*ptr_min=&min;
- for(i=1;i<=10;i++)
- {
- ptr =&no[i];
- if(*ptr<*ptr_min)
- *ptr_min=*ptr;
- }
- printf("最小值為:%d\n",*ptr_min);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement