因期末考 老師出了十題 需要解其中之過程 麻煩高手代解 謝謝
/*bubble-sort*/
main()
{
int n,i,j,t,k={9999,3,7,5,4,2,1,8,6},comp,change;
comp=0;
change=0;
n=8;
for (i=1;i<=n-1;i++)
for(j=n;j>=i+1;j--)
{
comp=comp+1;
if(k-k<0)
{
change=change+1;
t=k;
k=k;
k=t;
}
}
for(i=1;i<=n;i++)
printf("%d ",k);
printf("\ncomp=%d change=%d",comp,change);
}
/*double loop*/
main()
{
int n,s,i,p,j;
scanf("%d",&n);
s=0;
for (i=1;i<=n;i++)
{
p=1;
for (j=1;j<=3;j++)
p=p*j;
s=s+p;
}
printf("s=%d",s);
}
/*alternative GCD*/
main()
{
int a,b,r,k;
scanf("%d %d",&a,&b);
a_rtn:
k=a/b;
r=a-k*b;
a=b;
b=r;
if(r!=0)goto a_rtn;
printf("%d",a);
}
/*continue statement exercise*/
main()
{
int i,p;
p=1;
for (i=2;i<=30;i=i+2)
{
if(i%5!=0) continue;
p=p*i;
}
printf("p=%d",p);
}
/*s=1+4+8+13+19+26+34+...+n*/
main()
{
int n,s,k,i;
scanf("%d", ..
訪客只能看到部份內容,免費 加入會員 或由臉書 Google 可以看到全部內容