1、
#include<stdio.h> #include<string.h> /* char *itoa(int a){ static char b[20]; int i=0,l; char t; while(a!=0){ b[i]='0'+a%10; a=a/10; i++; } b[i]='\0'; l=strlen(b); for(i=0;i<l/2;i++){ t=b[l-1]; b[l-1]=b[i]; b[i]=t; l--; } return b; } */ int main(){ char *itoc(int a,char str[]); int a; char str[11]; char *b; printf("please input a number:"); scanf("%d",&a); b = itoc(a,str); printf("%s\n",b); return 0; } char *itoc(int a,char str[]){ char stack[10]; int top; int i=0,x; top = -1; while(a!=0){ x = a%10; top++; stack[top] = '0'+x; a = a/10; } while(top>-1){ str[i]=stack[top]; top--; i++; } str[i]='\0'; return str; }
2、
#include<stdio.h> #include<stdlib.h> #include<time.h> #define N 5 int main(){ void maxn(int a[][5],int n,int *x,int *y,int *max); int a[N][N]; int i,j; int x,y,max; srand((unsigned)time(NULL)); for(i=0;i<N;i++){ for(j=0;j<N;j++){ a[i][j]=rand()%100; printf("%4d",a[i][j]); } printf("\n"); } maxn(a,N,&x,&y,&max); printf("max=%d,x=%d,y=%d\n",max,x,y); return 0; } void maxn(int a[][5],int n,int *x,int *y,int *max){ int i,j; *max=a[0][0]; for(i=0;i<n;i++){ for(j=0;j<n;j++){ if(*max<a[i][j]){ *max=a[i][j]; *x=i+1; *y=j+1; } } } }
标签:字符,int,top,char,二维,str,include,数转 From: https://www.cnblogs.com/gunancheng/p/17413058.html