ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1079. Maximum

help
Posted by xxsp 26 Apr 2007 20:23
the same program written in c++ is right ,but in c is Compilation error.
why??
c++:
#include<iostream>
using namespace std;

int a[100000];

int main(){
    a[0]=0;
    a[1]=1;
    for(int i=2;i<100000;i++)
        if(i%2)
            a[i]=a[i/2]+a[i/2+1];
        else
            a[i]=a[i/2];
    int n;
    while(cin>>n&&n){
        int max=0;
        for(int j=0;j<=n;j++)
            if(a[j]>max)
                max=a[j];
        cout<<max<<endl;
    }
    return 0;
}
c:
 #include<stdio.h>

int main(){
    int a[100000];
    a[0]=0;
    a[1]=1;
    for(long i=2;i<100000;i++)
        if(i%2)
            a[i]=a[i/2]+a[i/2+1];
        else
            a[i]=a[i/2];
    int n;
    while(scanf("%d",&n)&&n){
        int max=0;
        for(int j=0;j<=n;j++)
            if(a[j]>max)
                max=a[j];
        printf("%d\n",max);
    }
    return 0;
}
thank you!

Edited by author 26.04.2007 20:24