|
|
back to boardHelp me!!! I have a Compilation ERROR! My Source: #include <stdio.h> int nok(int a,int b) { int a1=a,b1=b; while (a!=b) { if(a>b) a-=b; else b-=a; } return(a1*b1/a); } int main() { int n,per[1010]; int a[1010]; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&per[i]); a[i] = 0; } for(i=1;i<=n;i++) { if(a[i]==0) { a[i]=1; int pos = per[i]; while(pos!=i) { pos = per[pos]; a[i]++; } pos = per[i]; while(pos!=i) { a[pos] = a[i]; pos = per[pos]; } } } for(i=2;i<=n;i++) { a[i] = nok(a[i-1],a[i]); } printf("%d",a[n]); return(0); } Re: Help me!!! I have a Compilation ERROR! "for (int i = 0..." isn't accepted, declare i separately |
|
|