1.
#include <stdio.h> void findByPoint(int *, int, int *, int *); void find(int *a, int n, int max, int min); int main(void) { int max1=0, min1=0, a[]={5,3,7,9,2,0,4,1,6,8}; findByPoint(a,10,&max1,&min1); //自定义函数,指针变量是a,max,min,&max1是地址。; printf("数组a最大和最小元素下标是%d,%d ", max1, min1); int max2=0, min2=0,b[]={3,4,71,9,2,7,4,2,6,90}; find(b,10,max2,min2); //自定义函数,指针变量是b,max,min,&max2是地址。 printf("数组b最大和最小元素下标是%d,%d ", max2, min2); return 0; } void findByPoint(int *a, int n, int *max, int *min) { int i; *max=*min=0; for (i = 1; i < n; i++) { if (a[i] > a [*max])*max=i; //*max指的是max的值,把i的值给*max if (a[i] < a [*min])*min=i; //*min指的是min的值,把i的值给*min } } void find(int *a, int n, int max, int min) { int i; for (i = 1; i < n; i++) { if (a[i] > a [max])max=i; //max是变量,i的值给max if (a[i] < a [min])min=i; //min是变量,i的值给min } printf("数组b最大和最小元素下标是%d,%d ", max, min); }
2.
#include <stdio.h> #include <string.h> //自定义一个字符串函数 void count(char s[],int *pdight,int *pletter,int *pother) { // int n; int i; n=strlen(s); for(i=0;i<n;i++){ if(s[i]>=65&&s[i]<=122) (*pletter)++; else if(s[i]>=48&&s[i]<=57) (*pdight)++; else (*pother)++; } } int main() { char s[100]; int dight=0; int letter=0; int other=0; gets(s); count(s,&dight,&letter,&other); printf("%d %d %d ",dight,letter,other); return 0; }