C语言二维字符数组问题

Python021

C语言二维字符数组问题,第1张

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <time.h>

int funtest(char cp[]) {

int ix = 0,iy = 0,ik = 0

char ca[20] = {'\0'},cb[20] = {'\0'}

// srand((unsigned)time(NULL))

strcpy(ca,cp)

ik = strlen(ca)

ix = rand()%ik

iy = rand()%ik

while(iy == ix) iy = rand()%ik

ca[ix] = '*'

ca[iy] = '*'

printf("The word is: %s.\n",ca)

printf("Please input correct word : ")

gets(cb)

return (strcmp(cb,cp) == 0)

}

void main() {

char cs[5][20] = {"beautiful","student","China","function","include"}

int i,ik = 0

srand((unsigned)time(NULL))

i = rand()%5

ik = funtest(cs[i])

if(ik) printf("Right!\n")

else printf("Wrong! The word is: %s\n",cs[i])

getchar()

}

第一个for循环,将a[0]到a[9]赋值为0~9

a=0,1,2,3,4,5,6,7,8,9

第二个for循环,i=0 1 2

于是

p[0]

=a[0*(0+1)]

=a[0]

=0

p[1]

=a[1*(1+1)]

=a[2]

=2

p[2]

=a[2*(2+1)]

=a[6]

=6

第三个for循环 i=0 1 2

k+=p[0]*2=0*2=0

k=5+0=5

k+=p[1]*2=2*2=4

k=5+4=9

k+=p[2]*2=6*2=12

k=9+12=21

输出k为21

选B