22无限循环注册_C语言循环结构习题及答案

点击蓝字

关注我们 FOLLOW US

1.下列程序段执行后s的值为(D )。

  int i=5, s=0;
  while(i--)  
      if (i%2) continue;
      else s+=i;

A.15

B.10

C.9

D.6

2.下列程序段执行后s值为_D_。

int i=5, s=0;
while(i--)  
   if (i%2) continue;
   else s+=i;

A.15

B.10

C.9

D.6

3.Among the following statements, _A_ is equivalent to while( *s++ = *t++ );.

A.do { *s = *t++; } while ( *s++ );

B.while ( *t ) *s++ = *t++;

C.do { *s++ = *t++; } while ( *t );

D.while ( *s ) *s++ = *t++;

4.设有程序段

int m=20; while (m=0) m=m++;

则下面描述中正确的是( C)。

A.while 循环执行 10 次

B.循环是无限循环

C.循环体语句一次也不执行

D.循环体语句执行一次

5.下面的这个循环的循环次数是(B )。 

for(int i=0,j=10; i=j=10; i++,j--)

A.语法错误,不能执行

B.无限次

C.10

D.1

6.对下列代码的描述:

#include "stdio.h"
int main(){
   long num=1;
   while(num++ > 0) for(long i=num; i >=0; i--)printf("i :=\n \t %ld \n" , i);
   return 0;
}

正确的是:C

A.程序有编译错误,不能执行

B.循环条件永为真,循环无限次,程序根本停不下来,打印输出无限行

C.循环有限次,程序正常结束,打印输出有限行

D.程序运行过程必定会出错(崩溃),结果打印输出有限行

7.以下正确的描述是( B)。

A.continue语句的作用是结束整个循环的执行

B.只能在循环体内和switch语句体内使用break语句

C.在循环体内使用break语句或continue语句的作用相同

D.从多层循环嵌套中退出时, 只能使用continue语句

8.C语言中while和do-while循环的主要区别是(A)。 

A.do-while的循环体至少无条件执行一次

B.while的循环控制条件比do-while的循环控制条件严格

C.do-while允许从外部转到循环体内

D.do-while的循环体不能是复合语句

9.下列叙述中正确的是(C)。

A.break 语句只能用于 switch 语句体中

B.continue语句的作用是使程序的执行流程跳出包含它的所有循环

C.break 语句只能用在循环体内和 switch 语句体内

D.在循环体内使用 break语句和 continue 语句的作用相同

10.执行以下循环语句时,下列说法正确的是(A)。

x = -1;
do {
     x = x * x;
} while (x == 0);

A.循环体将执行一次

B.循环体将执行两次

C.循环体将执行无限次

D.系统将提示有语法错误

11.假设变量s、a、b、c均已定义为整型变量,且a、c均已赋值(c大于0),则与以下程序段功能等价的赋值语句是(B)。

s = a;  
for(b = 1; b <= c; b++)
     s = s + 1;

A.s = a + b;

B.s = a + c;

C.s = s + c;

D.s = b + c;

12.以下程序段的输出结果是(B)。

int main(void)
{  
     int  num = 0, s = 0;
     while(num <= 2){
   num ++;
           s += num;  
     }
     printf("%d\n",s);  
     return 0;
}

A.10

B.6

C.3

D.1

13.运行以下程序后,如果从键盘上输入65 14,则输出结果为(C)。

int main(void)
{  
     int  m, n;
     printf("Enter m,n;");  
     scanf("%d%d", &m,&n);
     while (m != n)
     {   while (m > n)       m = m - n;
         while (n > m)       n = n - m;    
     }
     printf("m=%d\n",m);    
     return 0;
}

A.m=3

B.m=2

C.m=1

D.m=0

14.在100-999的自然数中,若将组成这个数的三个数字认为是三条线段的长度,那么是三条线段组成一个等腰三角形(包括等边)的共有多少个(C)

A.45

B.156

C.165

D.142

15.7的2014次方这个数的十位数是(A)

A.4

B.1

C.5

D.7

16.边长为n的正方形可以分为多个边长为1的正方形,如:边长为2的正方形有2*2个边长为1的正方形和一个边长为2的正方形,问边长为5的正方形有几个正方形(C) 

A.25

B.30

C.55

D.100

17.对于循环while(!e) 语句,!e等价于__AD。 

A.e==0

B.e!=0

C.e==1

D.e!=1

18.循环 for(i=0, j=5; ++i!=--j; ) printf(“%d %d”, i, j); 将执行_。

A.6

B.3

C.0

D.无限次

19.一下描述正确的是(C)

A.while,do_while,for循环中的循环体语句都至少被执行一次

B.do_while语句中while(表达式)后面的分号可以省略

C.while循环体中,一定要有能使while后面表达式变为假的操作

D.do_while循环中,根据情况可以省略while

20.如下程序的执行结果是(C)

#include
int main (void)
{int i, sum = 0;
for ( i = 1; i <= 3; sum ++ )
sum += i ;
printf ("%d\n", sum);
return 0;
}

A.6

B.3

C.死循环

D.0

21.设变量已正确定义,则以下能正确计算f=n!的程序段是 (D)

A.f=0;
for(i=1;i<=n;i++)f*=i;

B.f=1;
for(i=1;i

C.f=1;
for(i=n;i>1;i++)f*=i;

D.f=1;
for(i=n;i>=2;i--)f*=i;

22.下列程序段的功能是 (D)

#include
int main (void)
{int i, s = 0;
for (i = 1; i < 10; i += 2)
s += i + 1;
printf("%d\n", s);
return 0;
}

A.自然数1~9的累加和

B.自然数1~10的累加和

C.自然数1~9中的奇数之和

D.自然数1~10中的偶数之和

23.等比数列的第一项a=1,公比q=2,下面程序段计算前n项和小于100的最大n。程序[(1)]处应填 (C)

#include
int main (void)
{int a, q, n, sum;
a = 1; q = 2;
for (n = sum = 0; sum < 100; n++) {
sum += a;
a *= q;
}
[       (1)         ] ;
printf("n = %d\n", n);
return 0;
}

A.空行

B.n-=2

C.n--

D.n++

24.下面程序运行时如果输入“-1 2 3 3 6 2”,则输出结果是(B)

#include
int main(void)
{int t, a, b, i;
for (i = 1; i <= 3; i++) {
scanf("%d%d", &a, &b);
if (a > b)t = a - b;
else if (a == b)t = 1;
else t = b - a;
printf("%d", t);
}
return 0;
}

A.304

B.314

C.134

D.316

25.下列程序运行时输入“7mazon”,则输出结果是 (A)

#include
int main(void)
{char c;
int i;
for (i = 1; i <= 5; i++) {
c = getchar();
if (c >= 'a' && c <= 'u')c += 5;
else if (c >= 'v' && c <= 'z')c = 'a' + c - 'v';
putchar(c);
}
return 0;
}

A.7rfet

B.7rfets

C.rfet

D.rfets

26.执行下面的程序后变量a的值是 (A)

#include
int main(void)
{int a, b;
for (a = 1, b = 1; a <= 100; a++) {
if (b > 10)break;
if (b % 3 == 1) {
b += 3;
continue;
}
b -= 3;
}
printf("%d\n", a);
return 0;
}

A.5

B.6

C.7

D.8

27.下列程序段的输出结果是 (B)

#include
int main(void)
{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);
return 0;
}

A.x=4

B.x=8

C.x=6

D.x=12

28.以下程序段的输出结果是 (A)

#include
int main(void)
{int i = 0, s = 0;
do {
if (i % 2) {i++; continue;}
i++; s += i;
} while (i < 7);
printf("%d\n", s);
return 0;
}

A.16

B.12

C.28

D.21

29.以下程序段若要使输出值为2,则应该从键盘给n输入的值是 (B)

int s = 0, a = 1, n;
scanf("%d", &n);
do {
s += 1; a = a - 2;
} while (a != n);
printf("%d\n", s);

A.-1

B.-3

C.-5

D.0

30.要求以下程序的功能是计算:s=1+21 + 31 + ... + 101,但运行后输出结果错误,导致错误结果的程序行是(C)

#include
int main(void)
{int n; float s;
s = 1.0;
for (n = 10; n > 1; n--)s = s + 1 / n;
printf("%6.4f\n", s);
return 0;
}

A.int n; float s;

B.for (n = 10; n > 1; n--)

C.s = s + 1 / n;

D.s = 1.0;

31.以下程序段的输出结果是(B)

int i, j;
for (i = 1; i < 4; i++) {
for (j = i; j < 4; j++)
printf("%d * %d = %d  ", i, j, i * j);
printf("\n");
}

A.1 * 1 = 1  1 * 2 = 2  1 * 3 = 3
2 * 1 = 2  2 * 2 = 4
3 * 1 = 3

B.1 * 1 = 1  1 * 2 = 2  1 * 3 = 3
2 * 2 = 4  2 * 3 = 6
3 * 3 = 9

C.1 * 1 = 1
1 * 2 = 2  2 * 2 = 4
1 * 3 = 3  2 * 3 = 6  3 * 3 = 9

D.1 * 1 = 1
2 * 1 = 2  2 * 2 = 4
3 * 1 = 3  3 * 2 = 6  3 * 3 = 9

32.以下程序段的输出结果是 (A)

int i;
for (i = 1; i <= 5; i++) {
if (i % 2)printf(" else continue;
printf(" >");
}
printf("$");

A.< > < > < >$

B.< < < $

C.< > < > $

D.< < < > > > $

33.若i,j已定义为int类型,则以下程序段中内循环体的总的执行次数是(A)

for (i = 5; i; i--)
   for (j = 0; j < 4; j++) {...}

A.20

B.25

C.24

D.30

34.以下程序段的输出结果是 (B)

int i, j;
for (j = 10; j < 11; j++)
for (i = 9; i == j - 1; i++)
printf("%d", j);

A.11

B.10

C.9

D.10 11

35.以下程序段的输出结果是 (B)

int n = 9;
while (n > 6) {
n--;
printf("%d", n);
}

A.987

B.876

C.8765

D.9876

36.以下程序段的输出结果是 (b)

int x = 23;
do {
printf("%d", x--);
} while (!x);

A.321

B.23

C.22

D.死循环

37.在下列给出的表达式中,与while(E)中的(E)不等价的表达式是 (c)

A.(!E==0)

B.(E>0 || E<0)

C.(E==0)

D.(E!=0)

38.要求通过while循环不断读入字符,当读入字母N时结束循环。若变量已正确定义,下列程序段正确的是(A) 

A.while ((ch = getchar()) != 'N')printf("%c", ch);

B.while (ch = getchar() != 'N')printf("%c", ch);

C.while (ch = getchar() == 'N')printf("%c", ch);

D.while ((ch = getchar()) == 'N')printf("%c", ch);

39.若变量已正确定义,要求程序段完成求5!的计算,以下不能完成此操作的是(B)

A.for (i = 1, p = 1; i <= 5; i++) p *= i;

B.for (i = 1; i <= 5; i++) {p = 1; p *= i;}

C.i = 1; p = 1; while (i <= 5) {p *= i; i++;}

D.i = 1; p = 1; do {p *= i; i++;} while (i <= 5);

40.下列程序段输出结果为 _A_。

int a=1,b=2,c=2,t;
while(aprintf( "%d,%d,%d", a, b, c);

A.1,2,0

B.2,1,0

C.1,2,1

D.2,1,1

41.下列程序段或语法错误,或执行后s值为_C_。

int i=5, s=0;
do  
  if (i%2) continue;
  else s+=i;
while (--i);

A.15

B.9

C.6

D.语法错误

42.以下( )for语句是不能编译的?(B)

A.for(i=0; i<10, j<10; i++);

B.for(i=0; j=0; i<10; i++ );

C.for(i=0; i<10; i--);

D.for(i=0; j<10; j++);

43.以下程序段( C)的功能是计算序列 1 + 1/2 + 1/3 + ... 的前N项之和。

A.int i, n, sum;
scanf("%d", &n);
sum = 0;
for (i = 1; i <= n; i++){
sum = sum + 1.0/i;
}

B.int i, n;
double sum;
scanf("%d", &n);
for (i = 1; i <= n; i++){
sum = sum + 1.0/i;
}

C.int i, n;
double sum;
scanf("%d", &n);
sum = 0;
for (i = 1; i <= n; i++){
sum = sum + 1.0/i;
}

D.int i, n;
double sum;
scanf("%d", &n);
sum = 0;
for (i = 1; i <= n; i++){
sum = sum + 1/i;
}

E.int i, n;
double sum;
scanf("%d", &n);
sum = 0;
for (i = 1, i <= n, i++){
sum = sum + 1.0/i;
}

44.以下程序段(D )的功能是计算n的阶乘,假设计算结果不超过双精度范围。

A.int i, n;
double product;
scanf("%d", &n);
product = 0;
for (i = 1; i <= n; i++){
 product = product * i;
}

B.int i, n, product;
scanf("%d", &n);
product = 1;
for (i = 1; i <= n; i++){
 product = product * i;
}

C.int i, n;
double product;
scanf("%d", &n);
for (i = 1; i <= n; i++){
 product = product * i;
}

D.int i, n;
double product;
scanf("%d", &n);
product = 1;
for (i = 1; i <= n; i++){
 product = product * i;
}

45以下(C )循环并非重复5次?

A.int i;
for (i=1; i<6; i++) {}

B.int i;
for (i=0; i<5; i++) {}

C.int i;
for (i=0; i<=5; i++) {}

D.int i;
for (i=1; i<=5; i++) {}

46.若变量已正确定义,对以下while循环结束条件的准确描述是(A)。

flag = 1;
denominator = 1;
item = 1.0;
pi = 0;
while(fabs(item) >= 0.0001){
    item = flag * 1.0 / denominator;
    pi = pi + item;
    flag = -flag;
    denominator = denominator + 2;
}

A.item的绝对值小于0.0001

B.item的绝对值大于0.0001

C.item的绝对值等于0.0001

D.item的绝对值不等于0.0001

47.若变量已正确定义,以下while循环正常结束时,累加到pi的最后一项item的值满足(C )。 

flag = 1;
denominator = 1;
item = 1.0;
pi = 0;
while(fabs(item) >= 0.0001){
   pi = pi + item;
   flag = -flag;
   denominator = denominator + 2;
   item = flag * 1.0 / denominator;
}

A.item的绝对值小于0.0001

B.item的绝对值大于0.0001

C.item的绝对值大于等于0.0001

D.item的绝对值小于等于0.0001

48.执行以下程序段后,变量i的值是(B )。

int i = 10;
while ( i > 3 ) {
   i /=2;
}

A.1

B.2

C.3

D.5

49.执行以下程序段后,变量i的值是(B ) 

int i = 2;
do {
  i += 5;
} while (i < 15);

A.16

B.17

C.20

D.21

50.int a=1,b=2,c=3,t; while(a

A.1,2,0

B.2,1,0

C.1,2,1

D.2,1,1

605aeeeb5b27a779177924d522ce1d8d.gif

发现“分享”“赞”了吗,戳我看看吧

  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值