You are not logged in. Please login at www.codechef.com to post your questions!

×

runtime error in codeblocks and ideone

i have experienced many times that a certain program runs well in code blocks but give runtime error in ideone. Is it due to some optimizations by the compiler?? How to turn them off?

This question is marked "community wiki".

asked 28 Mar '15, 13:17

rishu97kr's gravatar image

2★rishu97kr
2529
accept rate: 0%

are you asking about turning off the optimizations of code blocks or ideone ?

(28 Mar '15, 13:34) arun_as1★
2

Give situations (elaboration with code) where this is happening.
Maybe you are supplying optimization flags to your local compiler used by code::blocks.

(28 Mar '15, 14:06) mediocoder3★

what i meant was that the code::blocks compiler is not showing runtime error but ideone is showing so for the same test cases.

see this question which was answered by @mediocoder

http://discuss.codechef.com/questions/67011/transform-the-expression

(for eg:- if you don't terminate a string with '\0' and print it then it will show run time error in ideone but will perfectly work in code::blocks as it was the case in above link)

(28 Mar '15, 21:39) rishu97kr2★

similar problem with this code also

include <iostream>

include <stdlib.h>

using namespace std; int calculate(int year); int leap(int y); int main() {int i,j,num,year,arr[100]; cin>>num;

for (i=1;i<=num;i++){ cin>>arr[i]; } for (j=1;j<=num;j++){ calculate(arr[j]);

}

} int calculate(int year) {int no;

no=year-2001; no=abs(no); no=no+leap(year);

if(no%7==0){cout<<"Monday\n";} else if(no%7==1){cout<<"tuesday\n";} else if(no%7==2){cout<<"wednesday\n";} else if(no%7==3){cout<<"thursday\n";} else if(no%7==4){cout<<"friday\n";} else if(no%7==5){cout<<"saturday\n";} else if(no%7==6){cout<<"sunday\n";} } int leap(int y){ int error=0; if(y>2001){ for(int i=y;i>2001;i--){ if(i%4==0){ if(i%100==0){ if(i%400==0){error++;} else {break;} }

             else if(i%100!=0){error++;}

            }
    }
}
else if(y<2001){
    for(int i=y;i<2001;i++){
            if(i%4==0){
                    if(i%100==0){ if(i%400==0){error++;}  }




             else if(i%100!=0){error++;}

            }
    }
}

else if (y=2001){error++;} return error-1; }

link

answered 18 Sep '15, 22:34

a194's gravatar image

0★a194
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×2,739
×2,476
×545
×235
×46

question asked: 28 Mar '15, 13:17

question was seen: 4,290 times

last updated: 18 Sep '15, 22:34