考研C语言步调治解题

[复制链接]
发表于 2026-1-2 01:10:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
步调治解题(指出步调实行的效果)
1. #include <stdio.h>
main( )
{ int i,j,x=0;
for (i=0;i<2;i++)
{ x++;
for (j=0;j<3;j++) { if (j%2 ) continue;
                     x++;
}
                x++;
             }
   printf(“x=%d\n”,x);
}
2. #include <stdio.h>
main( )
{ int k=0,j,x=0;
while (k<2)
{ ++x;
for (j=0;j<3;j++)
{ if (j%2 ) break;
   x++;
}
            k++; ++x;
           }
   printf(“x=%d\n”,x);
}
3.#include <stdio.h>
main()
{int a=2,b=7,c=5;
switch (a>0)
{case 1:switch (b<0)
       { case 1: printf(“$”);break;
         case 2: printf(“!”); break;
        }
case 0: switch (c= =5)
       { case 0: printf(“*”);break;
        case 1:printf(“#”);break;
        default: printf(“%”);
        }
default: printf(“&”);
} printf(“\n”);
}
4. main()
{ int i,sum=0;
  for (i=1;i<=50;i++)
   { sum+=i;
     if (sum>10) break;
     printf(“sum=%-5d\n”,sum);
}
 }
5. 若输入字符串program时,下列步调输出为:
#include <stdio.h>
main()
{ char str[80];
void prochar(char *str,char ch);
  scanf(“%s”,str);
  prochar(str,’r’);
  puts(str);
}
void prochar(char *str,char ch)
{ char *p;
  for (p=str;*p!='\0';p++)
     if (*p==ch){*str=*p;(*str)++;str++;}
  *str='\0';
}
6. #include <stdio.h>
      #include <string.h>
main()
{ int i,j,temp, d[4][4]={{1,2,3,4},{5,6,7,8},{4,3,2,1},{1,2,3,4}};
for (i=0;i<4;i++)
   for (j=0;j<i;j++)
       if (d[j]>d[j]) d[j]=d[j];
 for (i=0;i<4;i++)
  { printf("\n");
    for (j=0;j<4;j++)
    if (j>=i) printf("%6d",d[j] ) ;
    else printf("%6c",' ') ;
   }
 }
7. #include<stdio.h>
main()
{ int k;
  printf("\n");
  for (k=1;k<10;k++)
  switch(k%2)
    {case 0: printf("#");break;
     case 1: k+=2;printf("*");
     defalt: printf("\n");
     }
}
8.  int d=1;
  fun(int p)
  { static int d=5;
    d+=p;
    printf("(f)%-4d",d);
    return (d);
    }
   main()
    {int a=3;
     printf("\n(m)%d",fun(a*fun(d)));
    }
9. #include <stdio.h>
       main()
{char a[2][6]={"sun","moon"};
 int j,i,len[2];
 for(i=0;i<2;i++)
   { for (j=0;j<6;j++)
       if (a[j]=='\0')
          { len=j;
break;
}
     printf("%8s:%d\n",a,len);
    }
10. int x=2,y=4;
f1(int x)
{ x++;y++;
  printf(“f1:x=%d,y=%d\n”,x,y);
}
f2(int *y)
{ x++;(*y)++;
  printf(“f2:x=%d,y=%d\n”,x,*y);
}
   main()
{ int y=6;
  f1(x);f2(&y);
  printf(“main:x=%d,y=%d”,x,y);
}
 
步调治解题(指出步调实行的效果)
1. x=8
2. 步调输出为:x=6
3. 步调输出为:#&
4. 步调输出为: sum=1 sum=3 sum=6 sum=10
5.当键盘输入program.时,下列步调的输出: pogam
6. 步调输出为: 1 5 4 4 6 7 8 2 3 4
7. 步调输出为: * #* #*
8. 步调输出为:   (f)6 (f)24 (m)24
9 . sun:3 moon:4
10. f1:x=3 ,y=5 f2:x=3 ,y=7 main:x=3 ,y=7
 
 
 
 
 
 
 
 
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表