有以下程序 #include <stdio.h> int m1(int x, int y ) { if( x<= y ) return 2*x+1; else return y; } int m2(int x, int y )

admin2021-04-28  20

问题 有以下程序
#include  <stdio.h>
int  m1(int  x, int  y )
{  if( x<= y ) return 2*x+1;
   else  return   y;
}
int  m2(int  x, int  y )
{  if( x<= y ) return 2*y+1;
   else  return   x;
}
main()
{  int  i,  t1=10, t2=0;
   for( i=1; i<=4; i++ )
   {  t1=m1( i,t1 );    t2=m2( i,t2 ); }
   printf("t1=%d   t2=%d \n", t1, t2 );
}
程序运行后的输出结果是

选项 A、t1=9    t2=4
B、t1=4    t2=9
C、t1=9    t2=9
D、t1=1    t2=4

答案A

解析 函数m1(x,y),若x<y,返回2*x+1,否则返回y, 函数m2(x,y),若x<=y,返回2*y+1,否则返回x,for循环对t1=m1(i,t1),执行4次,可知答案为9,t2=m2(i,t2), 执行4次,可知答案为4,因此答案为A选项。
转载请注明原文地址:https://kaotiyun.com/show/tPtp777K
0

随机试题
最新回复(0)