CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Wiki » Tutorial for Input,Output

Tutorial for Input,Output

This post will try and introduce newcomers to the first and most basic thing they need to learn before submitting programs -- How to properly accept Input and print Output (I/O). I'll start off with a few guidelines and then conclude with an example from the CodeChef site.

For all the questions on our site, the input will be given to you from standard input (stdin for C users) and the result is expected on standard output (stdout for C users). This is the same as writing a program that accepts input from the keyboard and displays the results on the screen. I'm sure most of you have been programming that way already. However, a major difference is that you don't need to prompt the user for input, so stuff like:

"Please enter your name: "

are a big NO NO! You need to assume that the user entering the data at the other end knows what to enter and when to enter it. Similarly, while displaying the results, you need to display it in the exact format as is specified in the problem statement.

For figuring out the format in which data will be entered (given to you) and how you should display the results, you need to refer to the "Input" and “Output” section of the problem statement respectively. Please make sure that you are following the output specification to the decimal point. If you have one character out of place, your submission will be marked as incorrect

After reading the problem statement, you will be given a sample "Input” and the resulting expected “Output” your program should submit. Typically, you will be asked to run your program against multiple test cases. The number of test cases and the format of each test case will be clearly mentioned in the problem statement's "Input" section. More often than not, you will be required to display the result for each test case, so you will have as many results displayed as there are test cases.

Why so many test cases?

You must have studied about the different types of tests that you can run your program against in school. Some of them are:

  1. Boundary value testing
  2. Negative testing
  3. Stress testing
  4. and so on....

Now, each of these have a specific purpose, so the problem setter has kept many different types of tests to test the correctness and performance of your program for different types of inputs.

Let us move on to a specific example to see what is happening.

The problem we shall be tacking here is: Life, the Universe, and Everything

The problem statement:

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.

Input:

A list of integers separated by a new line.

Output:

All the integers before the integer '42'.

Sample Input:
1
2
88
42
99

Sample Output:

1
2
88

 

Here, the constraint on the input we have is that any input number n will be such that (0 <= n < 100).

The problem statement is pretty straightforward, but for this toy program, the problem setter may construct test cases where:

  1. The 1st number is 42
  2. The last number if 42
  3. There are 10000000 numbers before 42

The first 2 tests are boundary value tests, and the 3rd one is a performance test. Generally these problems have a time limit associated with them. You are required to solve the problem with the given constraints in the given time limit. This time limit is chosen such that a good solution in any language would be accepted.If you are stuck, the answers to this problem, in over 25 programming languages can be found at Sample Solutions

You can now go ahead and try out the problems in the easy set.


Comments

  • Login or Register to post a comment.

can the input have any no.of

kiruthi @ 28 Oct 2009 08:51 AM

can the input have any no.of numbers

is same input can be reapted

ajitesh_1185 @ 3 Nov 2009 10:52 AM

is same input can be reapted

#include<stdio.h> int

Phasor @ 14 Nov 2009 03:10 PM

#include<stdio.h>

int main()

{

while (1)

{

int i;

scanf("%d", &i);

if i == 42 break;

else

printf("%d/n",i);

}

}

 

 

 

 

oops.. didnt intent to post

Phasor @ 14 Nov 2009 03:14 PM

oops.. didnt intent to post that. sorry :)

#include<stdio.h> int

mahadevanrm @ 20 Nov 2009 11:47 AM

#include<stdio.h>

int main()

{

int i;

while (1)

{

scanf("%d", &i);

if (i!= 42)

{

printf("%d/n",i);

}

}

#include<stdio.h>int main(){

sandy.coder @ 27 Nov 2009 09:22 AM

#include<stdio.h>
int main()
{
int num;
while(scanf("%d",&num)>0 && num!=42)
printf("%dn",num);
return 0;
}

My code is not uploading ..

najeeb @ 2 Dec 2009 10:43 PM

My code is not uploading .. Run time eroor is coming .. its working very fine GCC compiler..

When stops the input?  

aditya_pratap @ 18 Dec 2009 04:01 PM

When stops the input?

 

IF 2 TIMES 42 REPEAT THEN

aditya_pratap @ 18 Dec 2009 05:32 PM

IF 2 TIMES 42 REPEAT THEN WHATWE DO?

lol why choose an easy

Dudio @ 27 Dec 2009 09:41 PM

lol why choose an easy problem like life & the universe? How do you terminate input on TurboSort (Easy) ?

 

I'm entering my data into vectors but I don't know how to terminate it when the input is done. For example, I know max input is 1000000 integers, what do I do if the user wants to stop before that?

That problem tells you

triplem @ 28 Dec 2009 02:03 AM

That problem tells you exactly how many numbers you should read before stopping, on the first line.

hi please tell me what is the

gauravforyouall @ 12 Jan 2010 12:47 PM

hi please tell me

what is the problem in

#include <stdio.h>

int main()

{

int i;

do{

scanf("%d",&i);

 

if(i<42)

{

printf("%dn",i);

}

}while(i<42);

 

 

}

 

 

 

 

Describe what you are doing

triplem @ 12 Jan 2010 12:57 PM

Describe what you are doing in words. Then read the problem. Your error is obvious.

#include<stdio.h>   int

hero @ 21 Jan 2010 12:38 PM

#include<stdio.h>

 

int main()

{

int i;

scanf("%d",&i);

if(i!=42)

{

printf("%d",i);

}

 

}

 

#include<stdio.h> int

hero @ 21 Jan 2010 12:41 PM

#include<stdio.h>

int main()

{

int i;

scanf("%d",&i);

do

{

printf("%d",&i);

}while(i!=42)

}

 

FAQ

triplem @ 21 Jan 2010 01:16 PM

FAQ

@Gaurav   it straight forward

abhityagi85 @ 28 Jan 2010 05:03 PM

@Gaurav

 

it straight forward that the number read should not be 42. we dont have to compare it with lesser than or greater than 42. This is what u r doing.

 

Also the horrible thing i found in your code is checking number in while() as well as inside while. Why cant you just check once, then continue loop and print it every time u are able to read coz of condn met.

 

like this

 

cin>>n;

 

while(n!=42)

{

cout<<"n"<<n;

cin>>n;

}

 

Its pretty simple. Isn't it????

continued from prev

abhityagi85 @ 28 Jan 2010 05:05 PM

continued from prev post...

 

logic is ok but

cin and cout wouldnt work. try stream reading using fread(), fgets()

#include<stdio.h> void

Nazrul Islam @ 4 Feb 2010 01:12 PM

#include<stdio.h>

void main()

{

int i;

scanf("%d",&i);

for(i=1;i<42;i++)

printf("%d",i);

getch();

}

why we can not use conio.h

udit_rastogi @ 16 Feb 2010 05:49 PM

why we can not use conio.h

Because it is not a standard

triplem @ 17 Feb 2010 01:59 AM

Because it is not a standard header file.

import

cool_rayat @ 28 Feb 2010 10:34 PM

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Life_the_Universe_and_Everything {
public static void main(String str []) throws NumberFormatException, IOException
{     System.out.println("Enter no of digit u wann enter ");
BufferedReader ob1= new BufferedReader(new InputStreamReader(System.in));
int user_choice= Integer.parseInt(ob1.readLine());
// Enter number in array

int num_hold[]=new int[user_choice];
System.out.println("Entre "+user_choice+" numbers ");
for(int i=0;i<num_hold.length;i++)
{
BufferedReader ob2= new BufferedReader(new InputStreamReader(System.in));
int num= Integer.parseInt(ob2.readLine());
num_hold[i]=num;
}



System.out.println("------------------------");         
for(int m=0;m<num_hold.length;m++)
{
int temp=num_hold[m];

if(temp<=88)
{   System.out.println(temp);
}
else{
break; 
}

}




}
}

 

whats wrong with this?

I am new here, can you please

Anirudh Kishan @ 9 Mar 2010 08:22 PM

I am new here, can you please tell where I am going wrong :-

#include <iostream.h>

void main()
{
int a;

while (1)
{
cin>>a;
if (a==42)
{
break;
}
cout<<"n"<<a<<"n";
}

}

" The problem statement: Your

satic_discharge @ 11 Mar 2010 06:44 PM

"

The problem statement:

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."

 

i think the given example is wrong

No it isn't.

triplem @ 12 Mar 2010 02:02 AM

No it isn't.

please buddy tell me how this

monster at bk5d3bs @ 1 Apr 2010 03:51 PM

please buddy tell me how this is working... how the input is being given.... i jus cant understand plz tell me....

FAQ

triplem @ 1 Apr 2010 03:53 PM

FAQ

Hi can someone tell how to

aniket134 @ 2 Jul 2010 11:18 PM

Hi can someone tell how to take input with Python?

ALSO TELL ME TOOO THAT HOW TO

solmri @ 3 Jul 2010 05:42 PM

ALSO TELL ME TOOO THAT HOW TO TAKE INPUT IN PYTHON AND PHP ???????????

dont we need an array for

sourabh_bose @ 10 Aug 2010 06:14 PM

dont we need an array for storng?

Hello, I am new in this

Sk.Razee @ 13 Sep 2010 02:15 AM

Hello, I am new in this website.Where is the problem at this code.I compiled it and run it in my Dev C++ 4.9.9.2.It worked but Codechef is showing it is wrong.I am getting upset to see that...You know this is a simple problem...:(

//Solution of Life, the Universe, and Everything

 

#include<iostream>

#include<stdio.h>

#include<stdlib.h>

 

 

using namespace std;

 

int main()

{

system("cls");

int n,*a=NULL,i=0;

cout<<"How many inputs do you have?"<<endl;

cin>>n;

a=new int[n];

cout<<"Input:"<<endl;

do

{

cin>>a[i];

i++;

}while(i<n);

cout<<"Output:"<<endl;

i=0;

while(i<n && a[i]!=42)

{

cout<<a[i]<<endl;

i++;

}

delete []a;

a=NULL;

system("pause");

return 0;

}

See the FAQ.

triplem @ 13 Sep 2010 02:35 AM

See the FAQ.

I want to know that.. how is

mrs.ronnie @ 14 Sep 2010 05:12 PM

I want to know that.. how is it supposed to work? like.. first user enter some inputs serially and then the outputs are shown ...if that is so and we cannot ask the user "enter input"..then how do I know when to stop taking input and show output??p

 

or is it like...enter one input, process it if it is not 42.. ?

 

which one ??

I agree with Israt.I am also

Sk.Razee @ 16 Sep 2010 12:40 AM

I agree with Israt.I am also confused how do the we make the compiler stop taking input and start to process????!!!!

There is also a problem that

Sk.Razee @ 16 Sep 2010 12:45 AM

There is also a problem that I saw successful submissions:

How could it be a successful submissions.It input output shouldn't match with the I/O given there...this simple program makes me crazy and stop me to go ahead...:(((

CodeChef submission 1526 (C) plaintext list. Status: AC, problem TEST, contest . By crashbird (Elijah), 2009-02-23 18:06:46.
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int t;
  5. while(1)
  6. {
  7. scanf("%d",&t);
  8. if(t==42)break;
  9. printf("%dn",t);
  10. }
  11. return 0;
  12. }

That program is perfectly

triplem @ 16 Sep 2010 04:39 AM

That program is perfectly correct. Why do you think it gives the wrong output?

plz help..... my codes

chetan_ug2k10 @ 16 Sep 2010 11:22 PM

plz help.....

my codes are:

 

 

#include<stdio.h>
int main()
{
int a[5],i;
for (i=0;i<5;i++)
{
scanf("%d",&a[i]);
if (a[i]!=42)
{

printf("%dn",a[i]);
}
else
{
break;
}
}
return 0;
}

 

 

 

i am getting correct output.

but here when i submit it shows wrong answer.

why..??

Your code will give the wrong

triplem @ 17 Sep 2010 03:07 AM

Your code will give the wrong answer if there are more than 5 numbers in the input.

#include<stdio.h>int main(){

sam_dc @ 19 Sep 2010 02:37 PM

#include<stdio.h>
int main()
{
int c,a[10000],i;
for(i=0;i<10000;i++)
{
scanf("%d",&c);
if(c>=0 && c<=99)
a[i]=c;
else
i--;
}
i=0;
while(a[i]!=42&&i<20000)
{
printf("%dn",a[i]);
i++;
}
return 0;
}
Is this code optimal?

#include int main() { int

ishanverma @ 22 Sep 2010 12:03 AM
#include int main() { int x,i; for(;;) { scanf("%d",&x); if(x>0&&x!=42) { printf("%dn",x); } else { break; } } return 0; } what's wrong in this program plz tell...........

Why did you put if (x>0) in

triplem @ 22 Sep 2010 03:18 AM
Why did you put if (x>0) in there? That will cause it to fail when x is 0.

This simple puzzle is

rameshwise @ 23 Sep 2010 11:06 PM
This simple puzzle is probably ill organised. according to sample codes you will not be able to input 99 in the input, this bit is pretty confusing for most peers here. few asked can we input 42 twice ? !!!! few were wondering if many numbers after 42 can be entered, because sample input shows 99 at the end... this leads to many assumptions. At very first view, I was wondering when this program should end, if you can enter something after 42 i.e. 99 Sample Input: 1 2 88 42 99 Sample Output: 1 2 88 Sample code input and output will come up mixed like this: 1 1 2 2 88 88 42. If you want input and output as shown. you have to store all input data in a light weight collection. print it at one stretch after program encounters 42, pretty misleading, isn't it.... in puzzles readers assumptions play big role... who knows authors' assumptions unless puzzle is certain...

There is nothing 'ill

triplem @ 24 Sep 2010 03:18 AM

There is nothing 'ill organised' about the problem at all.

All of the sample codes I have read allow for 99 as an input; why do you think they don't?

The problem statement doesn't say you can't enter 42 twice, so of course you aren't meant to assume you can't.

The sample input shows numbers appearing after 42 so it is clear that the input doesn't have to stop there.

As for 'mixing' input and output, I don't think you understand how output works. The input does not appear in the output stream whatsoever, and storing all numbers in a collection is a bad idea. Read the FAQ which is very clear about that.

i hav a code which runs

codechef19 @ 7 Oct 2010 10:16 PM

i hav a code which runs otherwise but give a run-time error after submission

the code is in python

def f():

x=raw_input("Enter a number")

l1=[]

l1.append(x)

while(x!=""):

x1=int(x)

l1.append(x1)

x=raw_input("Enter a number")

l=len(l1)

i=1

while(i<l):

if l1[i]!=42:

print l1[i]

else:

break

i=i+1

f()

I m New 2 codechef JAVA error

indar00 @ 10 Oct 2010 03:07 PM

I m New 2 codechef

JAVA error ===

Can any1 specify more on NZEC runtime error . i read the details given on the site about this error .

So, i placed the code ::::

System.exit(0);

and i also did handled the error with try , catch but the code still gives the error while uploading .

this code is compiling fine on my end .

i am really stuck with this error with past 3 days .!!!

I'm also using HashSet ,  TreeSet stuctures . Do i need to replace these data structures with ARRAY ...??

Help needed.,....

Is there any limit on the no.

chatterjee @ 10 Oct 2010 08:36 PM

Is there any limit on the no. of inputs???

time limit exceeded error for

rohanpkumbhar @ 27 Nov 2010 08:48 PM

time limit exceeded error for following code......plz help me reduce time consumption

 

#include<stdio.h>

int main(void)

{

unsigned int num;

for(;printf("%d",scanf("%d",&num)!=42););

return(0);

}

I CAN NOT UNDERSTAND  WHAT

sharifa_abedin @ 1 Dec 2010 09:16 AM

I CAN NOT UNDERSTAND  WHAT SHOULD I DO OR NOT

#include<iostream>   using

mohit_cpp @ 5 Dec 2010 11:38 PM

#include<iostream>

 

using namespace std;

 

int main( ) {

 

int a[5] ;

for( int i  = 0; i <= 4; i++ ) {

cin>> a[i];

}

for( int j = 0; j <= 4; j++ ) {

cout<<endl;

if( a[j] == 4 )

break;

cout<< a[j]<<endl;

}

return 0;

}

I am posting this code.. whats wrong in it... why it is giving wrong ans.. Anyone tell me..

Are you sure you are trying

triplem @ 6 Dec 2010 01:44 AM

Are you sure you are trying to solve the right problem? Your code doesn't seem to do anything that you are asked to do. For example, you are meant to keep reading until you read a 42, but you stop after 5 numbers, or stop after you read the number 4..

@Mohit U've compared the no

s3thu @ 11 Dec 2010 08:17 PM

@Mohit U've compared the no wit 4 instead of 42!

WHAT IS MY PLOBLEM TELL ME

dinarcse @ 7 Jan 2011 06:04 PM

WHAT IS MY PLOBLEM TELL ME PLESE

 

#include<stdio.h>
void main()

{
int i=0,a[100],j,d=0;

printf("n enter number(negetive to end.): ");

while(d>=0)
{ scanf("%d",&a[i]);
i++;
d=a[i];

}

printf("output: ");

for(j=0;j<i;j++)

{ if(a[j]==42)
break;
else
printf("%d ",a[j]);

}

}

#include <stdio.h>#include

lovelysurendar @ 27 Jan 2011 06:55 PM

#include <stdio.h>
#include <string.h>
int main()
{
int num[99];
int i,j,temp,a[99];
i=0;
while(scanf("%d",&num[i]))
{
if(num[i]!=42)
{
a[i]=num[i];
d=i;
i++;
}
else
{
break;
}
}
for(i=0;i<d;i++)
{
for(j=0;j<d;j++)
{
if(a[j]>a[i])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
return 0;
}

what wrong in this program Please anyone help me

while submitting it giving the error wrong answer

#include<iostream>using

luvlyangel @ 30 Jan 2011 08:49 AM

#include<iostream>

using namespace std;
int main()
{
int n;
for(int i=0; i<100;i++)
cin>>n;
for(int i=0; i<100;i++)
{
if(n==42)
break;
cout<<n<<"n";
}

return 0;
}


Smbdy plz tell me wts wrong in dis program...

Does the problem say to stop

triplem @ 30 Jan 2011 12:45 PM

Does the problem say to stop after reading 100 numbers?

#include<stdio.h>int

arifrhb @ 3 Feb 2011 03:43 PM

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

 

I want to submit it.... compile it using trubo c.....

then which language i select for it.

#include<iostream>#include<co

prachidubey19 @ 6 Apr 2011 06:36 PM

#include<iostream>
#include<conio.h>
int main()
{
int n;
for(int i=0; i<100;i++)
cin>>n;
for(int i=0; i<100;i++)
{
if(n==42)
break;
cout<<n<<"n";
}

return 0;
}

I'm new to this site and just

harish_8080 @ 15 Apr 2011 01:20 AM

I'm new to this site and just testing how things work.

what does M represents, because while doing Life universe problem, the first one in easy, it takes 177M while an almost same solution in the successful submission has 0.0M ?

Also, the input and output shown in the example, has to be in that order or we can take input then show output, then again run loop and take input then output. Because, I submitted the solution as shown in the example, but other submitted in other order and still got successful submission?

#include<stdio.h> #include<

saurabhzx @ 27 Apr 2011 04:54 PM

  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. int x;
  6. while(x!=42)
  7. {
  8. scanf("%d",&x);
  9. printf("n");
  10. printf("n%d",x);
  11. }
  12. getch();
  13. }
    why the compiler did not accept this program in this site...

#include<stdio.h> #include<

saurabhzx @ 27 Apr 2011 04:54 PM

  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. int x;
  6. while(x!=42)
  7. {
  8. scanf("%d",&x);
  9. printf("n");
  10. printf("n%d",x);
  11. }
  12. getch();
  13. }
    why the compiler did not accept this program in this site...

#include<stdio.h>#include<con

jituo007 @ 30 Apr 2011 10:44 PM

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("PLEASE ENTER ANY INTEGER NUMBER OF ONE OR TWO DISITS ");
do
scanf("%d",&n);
while(n!=42);
printf("nn42 found!!!nnPLEASE PRESS ANY KEY TO EXIT");
getch();
}

Here, the constraint on the

ronakag @ 12 May 2011 12:17 AM

Here, the constraint on the input we have is that any input number n will be such that (0 <= n < 100).

 

What shall i do if the number inputed is not within the range? Shall i exit the programme or ask user to input again?

 

If the problem statement

triplem @ 12 May 2011 09:15 AM

If the problem statement tells you that n will always be between 0 and 100, then n will always be between 0 and 100.

thnks Stephen

ronakag @ 12 May 2011 11:26 AM

thnks Stephen

import java.io.*; public

atuljangra @ 20 May 2011 02:52 AM
import java.io.*; public class code { public static void main(String a[])throws IOException{ System.out.println("enter the no"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String inputname; while(true){ inputname = br.readLine(); int x = Integer.parseInt(inputname); if(x==42){ break; } System.out.println(x); } } } whats wrong with this ?? how to upload java programs ?

#include int main() { int

laasya @ 31 Jul 2011 10:31 AM
#include int main() { int n; while(1) { scanf("%d",&n); if(n!=42) printf("%d",n); else if(n==42) break; } } what is the problem with this code??

#include void main() { int

rajesh0708 @ 10 Aug 2011 05:27 PM
#include void main() { int x; while(scanf("%d",&x)!=42) { printf("%dn",x); } }

#include void main() { int x;

rajesh0708 @ 10 Aug 2011 05:41 PM
#include void main() { int x; while(scanf("%d",&x)!=42 && x!=42) { printf("%dn",x); } }

#include int main() { int

bhalchandra @ 11 Aug 2011 02:30 PM
#include int main() { int i; while (1) { scanf("%d", &i); if (i!= 42) { printf("%d/n",i); } }

main() { int i; while(1) {

abhilash123 @ 17 Sep 2011 10:32 PM
main() { int i; while(1) { printf("n enter number"); scanf("%d",&i); if(i==42) break; else printf("%d",i); } getch(); }

hey, m getting a runtime time

aspea @ 2 Oct 2011 04:37 AM
hey, m getting a runtime time error, though the program is running on my java1.6, but its giving runtime error when compiled by 'codechef'..........please solve the problem, as soon as possible.

#include #include void

rock_raghavag @ 6 Oct 2011 10:23 PM
#include #include void main() { clrscr(); int a; printf("universe problem "); while(1) { scanf("%d",&a); if(a==42) { break; } else { printf("%d",a); } } while(1) { scanf("%d",a); } }

Can anybody tell me wats the

justkumar @ 31 Oct 2011 02:28 PM
Can anybody tell me wats the problem wid this code import java.io.*; class earth { public static void main(String args[])throws IOException { int n=0; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while(n!=42) { n=Integer.parseInt(in.readLine()); System.out.println(n); } System.exit(0); } }

#include #include void

cyber101 @ 6 Dec 2011 12:56 AM
#include #include void main() { clrscr(); int a[99],n; cout<<"number of inputs to be entered : "; cin>>n; cout<<"inputs:n"; for(int i=0;i>a[i]; } cout<<"OUTPUTS:n"; for(i=0;i

The equivalent code in Java

jawa2code @ 14 Dec 2011 07:18 AM
The equivalent code in Java is below: import java.util.Scanner; public class BoundBy42{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int i=0; while(true){ i=sc.nextInt(); if(i==42){ break; } System.out.println(i); } } } It is not compiled in Codechef server? may i know the reason,it is working in my syatem

where is the

madcoder @ 27 Dec 2011 04:23 PM
where is the problem? #include iostream using namespace std; int main() { int i; while(1) {cin>>i; if(i==42) break; else cout<

How do I know when to stop

vasavi_12 @ 8 Jan 2012 11:00 PM
How do I know when to stop reading the input?

whats wrong with

arpitsolanki14 @ 12 Jan 2012 09:24 PM
whats wrong with it #include int main() { int i; while(1) { scanf("%d",&i); if(i>=0&&i<=99) { printf("%d",i); if(i==42) { break; } } } return 0; }

#include #include void

surbhi289 @ 15 Jan 2012 01:59 PM
#include #include void main() { int a[10],k,n,i; clrscr(); printf(" ENTER THE NUMBERS YOU WANT TO ENTER : "); scanf("%d",&n); for(i=0;i

#include #include void

surbhi289 @ 15 Jan 2012 02:00 PM
#include #include void main() { int a[10],k,n,i; clrscr(); printf(" ENTER THE NUMBERS YOU WANT TO ENTER : "); scanf("%d",&n); for(i=0;i

this is not fair :(( why the

surbhi289 @ 15 Jan 2012 02:00 PM
this is not fair :(( why the hell my post is not seen fullllyyyyyyyyyyyyyyy

int a[10],k,n,i; clrscr();

surbhi289 @ 15 Jan 2012 02:01 PM
int a[10],k,n,i; clrscr(); printf(" ENTER THE NUMBERS YOU WANT TO ENTER : "); scanf("%d",&n); for(i=0;i

using System; namespace

aranjan6 @ 19 Jan 2012 01:57 PM
using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int[] list = new int[2506]; int i = 0; int z = 0; while(true) { z=int.Parse( Console.ReadLine()); list[i] = z; i++; if (z == 0) break; } int l=0; for(int k=0;k

Help help help what is error

pradeep160387 @ 7 Feb 2012 01:03 AM
Help help help what is error in my source code? #include #include int main() {int i; clrscr(); do {cin>>i; if(i>100&&i<-100&&i!=42) cout<

plz tell the problem with

rahul3110 @ 16 Feb 2012 12:26 AM
plz tell the problem with this code..!! import java.util.Scanner; class Test{ public static void main(String args[]){ Scanner s =new Scanner(System.in); int n; do{ n=s.nextInt(); }while(n!=42); } }

#include int main() {

kapish88 @ 14 Mar 2012 03:14 PM
#include int main() { int i,num[5]; for(i=0;i<5;i++) { scanf("%d",&num[i]); } for(i=0;i<5;i++) { if(num[i]==42) { break; } else { printf("%dn",num[i]); } } return(0); } what is wrong in this code??Please tell me problem

anybody tell me this in C#

kushwahapankaj @ 27 Mar 2012 10:40 AM
anybody tell me this in C#

class name should be Main

raghubharat @ 5 Apr 2012 08:51 PM
class name should be Main

Is it ok if cin and cout r

borleone @ 14 Apr 2012 07:27 PM
Is it ok if cin and cout r used? Coz i m used to that..

#include int main() { short

jeyanthinath @ 3 May 2012 01:56 AM
#include int main() { short int a; while (1) { scanf("%d",&a); if(a!=42) printf("%d",a); else break; } return(0); } gives run time error while upload using the gcc c compiler gives wrong output error while using the gcc c++ 4.0 compiler any one help me

Do i need to assume that

dharmendrascpm @ 7 May 2012 10:36 PM
Do i need to assume that ...every time input contains a num 42 ...thx in advance for rpy :)

#include void main() { int

nik258 @ 15 May 2012 06:23 PM
#include void main() { int i,j,arr[5]; for(i=0;i<5;i++) {scanf("%d",&arr[i]); } for(j=0;j<5;j++) { if(arr[j] == 42) { break; } printf("%d",arr[j]); } } WHAT THE PROBLEM IN THIS.........IT's RUNNING PERFECTLY ON TURBOC BUT NOT HERE

For those doing these tasks

crystalshardz @ 16 May 2012 06:14 PM
For those doing these tasks in PHP you should read your input using: $input=trim(fgets(STDIN)); Hope this helps

#include main() { int

aldiablo @ 20 May 2012 12:28 AM
#include main() { int n; do { scanf("%d",&n); if(n!=42&&n<100) printf("n%d",n); }while(n!=42&&n<100); } wats wrong in this ???? plzz tell me ... it shows runtime error !!!
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com