|
比较一下,就会知道goto用得好的话能使程序简洁
#includea<stdio.h>
#includea<stdlib.h>
#includea<time.h>
#defineaBOUNDa10
intamatrix[BOUND][BOUND][BOUND][BOUND]
intamain()
{
aaintai,j,k,l,sum=0;
aasrand((unsigned)time(NULL));
aafor(i=0;i<BOUND;i++)
aaaafor(j=0;j<BOUND;j++)
aaaaaafor(k=0;k<BOUND;k++)
aaaaaaaafor(l=0;l<BOUND;l++)
aaaaaaaaaaifa((matrix[j][k][l]=rand())==0)
aaaaaaaaaaaagotoaexit_pos;
aaaaaaaaaaelse
aaaaaaaaaaaasuma+=amatrix[j][k][l];
aaprintf("suma=a%d",sum);
aaexit_pos:
aaaareturna0;
}
#includea<stdio.h>
#includea<stdlib.h>
#includea<time.h>
#defineaBOUNDa10
intamatrix[BOUND][BOUND][BOUND][BOUND]
intamain()
{
aaintai,j,k,l,sum=0,b=0;
aasrand((unsigned)time(NULL));
aafor(i=0;i<BOUND;i++)
aa{
aaaafor(j=0;j<BOUND;j++)
aaaa{
aaaaaafor(k=0;k<BOUND;k++)
aaaaaa{
aaaaaaaafor(l=0;l<BOUND;l++)
aaaaaaaa{
aaaaaaaaaaifa((matrix[j][k][l]=rand())==0)
aaaaaaaaaaaa{ba=a1;break;}
aaaaaaaaaaelse
aaaaaaaaaaaasuma+=amatrix[j][k][l];
aaaaaaaa}
aaaaaaaaifa(b)abreak;
aaaaaa}
aaaaaaifa(b)abreak;
aaaa}
aaaaifa(b)abreak;
aa}
aaifa(!b)
aaaaprintf("suma=a%d",sum);
aareturna0;
} |
|