公告: 为响应国家净网行动,部分内容已经删除,感谢读者理解。
话题:编程用指针实现输入三个整数,求其中的最大值回答:#include "stdio.h" int getmax( int *p , int n) { int i, max_p; max_p = p[0]; for (i=1;ilt;n;i++) { if (p[i]gt; max_p ) max_p = p[i]; } return max_p; } int main( ) { int *p; int a[3]; int k; p = a; printf("please enter 3 int number:"); scanf( "%d%d%d", amp;p[0],amp;p[1],amp;p[2]); printf( "the max num=%d\n",getmax(p, 3)); getch(); return 0; } ===================================== 该程序在Turbo C 2.0 / win-TC / minw GCC 下运行通过
参考回答:#includelt;iostream.hgt; int max(int *p) { if (p*[0]gt;p*[1]) { p*[2]=p*[0]; else p*[2]=p*[1]; } return(p*[2]); } int mian() { int *p; int i; coutlt;lt;“请输入三个数:”; for(i=0;ilt;3;i++) cin*p[i] max(p[i]); coutlt;lt;"The max is "lt;lt;p[2]; }
话题:编程实现从键盘输入三个整数,输出三个整数的中间值回答:#include using namespace std;int get_mid(int a,int b,int c){if(a=b a=c){return b=c?b:c;}else if(a=b a{return a;}else if(a{return b=c?c:b;}else if(a =c){return a;}}void main(){int a,b,c;cina;cinb;cinc;cout}
参考回答:#includeusing namespace std;int main(){int x,y,z,sum;int average;coutcinxyz;sum = x + y + z;average = sum / 3.0;cout return 0;}话题:编写程序,实现从键盘输入三个数,找出其中最小值显示输出回答:#include int main(){int arr[3],min;printf("请输入三个整数中间用空格分开:\n");scanf("%d %d %d",arr[0],arr[1],arr[2]);if (arr[0] min = arr[0];}else {min = arr[1];}if (min arr[2]) {min = arr[2];}printf("min=%d\n", min);return 0;}这样行吗
参考回答:void main(){int i,j,min,a[];int max=0;printf("输入 5 个数:");for(i=0;iscanf("%d",a[i]);min=a[0];for(i=0;iif(a[i]max)max=a[i];for(i=0;iif(a[i]min=a[i]; printf("最大数为:%d",max);printf("最小数为:%d",min);}