Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 28-03-2011, 04:06 PM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: Mar 2011
Location: Tirupati
Posts: 8
Question Run time error??


Hello guyz,
I'm ravi and BTW in an attempt to solve a problem I encountered with the following error.
The problem is as follows:

Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.

Example

Input:
1
2
88
42
99

Output:
1
2
88

My code to solve the above problem is as follows:
<code>
#include <stdio.h>
void main()
{
int n,flag=0;
do
{
scanf("%d",&n);
if(n==42) flag=1;
}while(flag==0);
}

</code>

But the judge says there is a runtime error..
can any one tell me where the error is??
but it perfectly executing in my command prompt with GCC compiler.
Please help me asap.
gubbaraviteja is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 28-03-2011, 05:58 PM   #2 (permalink)
BIOS Terminator
 
nims11's Avatar
 
Join Date: Apr 2008
Location: Ranchi
Posts: 816
Default Re: Run time error??

use instead of <..></..>

hmm a codechef question..
u need to print out the numbers inputted before 42 also. also to prevent runtym error, change void main to int main and return 0; at the end of main.
the code below should work.
Spoiler:

Code:
#include <stdio.h>
int main()
{
int n=0;
while(1)
{
scanf("%d",&n);
if(n==42)
break;
printf("%d\n",n);
}
return 0;
}

all the best!!
nims11 is online now   Reply With Quote
Old 28-03-2011, 10:35 PM   #3 (permalink)
Right Off the Assembly Line
 
Join Date: Mar 2011
Location: Tirupati
Posts: 8
Question Re: Run time error??

Hello nims,
thank u for the reply and the problem got solved when void main() is replaced as you said, but why there is runtime error if we use void main()?
Is there any concept, can anyone clear this doubt please.

waiting for the reply..
gubbaraviteja is offline   Reply With Quote
Old 29-03-2011, 12:02 AM   #4 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
Default Re: Run time error??

^^ please Google it up.

some links to get you started ::

[29] Newbie Questions / Answers *Updated!*, C++ FAQ
Cprogramming.com FAQ > main() / void main() / int main() / int main(void) / int main(int argc, char *argv[])
int main() vs. void main()

its best if you stick with standards. doing so will prevent such situations like yours from happening

see:: http://www.ecma-international.org/pu...s/Ecma-372.htm
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
arpanmukherjee1 is offline   Reply With Quote
Old 29-03-2011, 10:50 AM   #5 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
Default Re: Run time error??

C1X is the planned new standard for the C programming language. You might want to check it.
C1X - Wikipedia, the free encyclopedia
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx
- by clinton

Advertisement




All times are GMT +5.5. The time now is 12:25 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2