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

×

# TEST - Editorial

Editorialist: SUSHANT AGARWAL

CAKEWALK

# PREREQUISITES:

Basic looping,Basic Input/Output

# PROBLEM:

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.

# EXPLANATION:

Please refer to the sample solution given by editorialist.

# EDITORIALIST'S SOLUTION:

Editorialist's solution can be found here.

This question is marked "community wiki".

asked 17 Dec '14, 14:23 21368
accept rate: 0% 19.8k350498541

 0 #include void main() { int a,flag=0; do { cin>>a; if(a<=99 && a>=(-99) && a!=42) { flag=1; cout<
 0 import java.util.*; public class inToOut{ public static void main(String [] args) { Scanner in = new Scanner(System.in); while(in.hasNextInt() ) { int temp = in.nextInt(); if(temp == 42) break; System.out.println(temp); } }  } answered 23 Jan '15, 16:46 0★lkalig2 1 accept rate: 0%

# include<stdio.h>

int main() {int i,b; for(i=0;i<100;i++) {scanf("%d\n",&b[i]); if(b[i]==42) break; else printf("%d\n",b[i]); } return 0;}

answered 27 Jan '15, 10:21 1★ashish66
1
accept rate: 0%

# include<stdio.h>

int main() { int a=1; while(a>=(-99) && a<=99) { scanf("%d",&a); if(a!=42) printf("%d\n",a); else break; } return 0; }

answered 01 Feb '15, 23:33 1
accept rate: 0%

# include<conio.h>

void main() { int x; printf("\n Enter a two digit no to stop enter 42 "); scanf("%d",&x); if((x>99)||(x=42)) break; else printf("the entered no is : %d",x); }

answered 11 Feb '15, 19:32 1
accept rate: 0%

Don't give statements like 'Enter number' etc. Directly take input and print output in the given format.

(11 Feb '15, 21:18)

# include<stdio.h>

main() { int num=0; while(num<100) { scanf("%d",&num); if(num!=42) printf("%d",num); else continue; }

answered 08 Mar '15, 23:27 1
accept rate: 0%

/this is corect answer even tho sowing false/

# include <stdio.h>

int main () {
int n;
for (;n!=42;)
{
scanf ("%d",&n);

printf ("%d\n",n);} return 0; }

answered 13 Mar '15, 22:47 0★prerak13
1
accept rate: 0%

 0 import java.util.Scanner; public class LifeTheUniverseAndEverything { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { int i = scanner.nextInt(); if (i == 42) break; System.out.println(i); } }  } answered 23 Mar '15, 14:30 1 accept rate: 0%

# include<stdio.h>

int main(void) { unsigned int num; for(;printf("%d",scanf("%d",&num)!=42);); return(0); }

answered 04 Apr '15, 20:34 0★prash_7
1
accept rate: 0%

 0 import java.util.Scanner; / * @author Avi / public class New { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here int poda[]; poda = new int; Scanner input = new Scanner(System.in); System.out.println("enter the array"); for (int i =0;i<5;i++) { poda[i]=input.nextInt(); } System.out.printf("the output values are "); for (int i =0;i<5;i++) { if(poda[i]==42) { break; } System.out.println(poda[i]); } }  } answered 02 May '15, 15:14 1 accept rate: 0%
 0 void main() { int i,a; a={1,42,84,7,8,9}; for(i=0;i<6;i++) { if(a[i]<=a[i+1]) {printf("%d",a[i]); printf("\n"); }else break; } getch(); } answered 13 May '15, 13:38 1 accept rate: 0%

# include<iostream.h>

using namespace std; main() { int n; cout<<"enter a number"; cin>>n; while(n>-99 && n<99 && n!=42) { cout<<"enter a no." cin>>n; cout>>n; }

answered 12 Jun '15, 22:51 1
accept rate: 0%

# include<conio.h>

void main() { int n; while(1) { printf("Enter the number:"); scanf("%d",&n); if(n==42) break; printf("%d",&n); } }

answered 13 Jul '15, 18:35 0★hbl_8212
1
accept rate: 0%

 0 my program is having a compile error: package codechef; import java.util.Scanner; public class chef { private static Scanner input; public static void main(String[] args) { input = new Scanner(System.in); int value = 0 ; do{ System.out.println("Enter a number: "); value = input.nextInt(); System.out.println(value); } while(value != 42); System.out.println("Program terminated"); }  } answered 29 Nov '15, 02:34 1 accept rate: 0%
 0 package package1; import java.util.Scanner; public class Class1 { public static void main(String[] args) throws Exception { while(true) { System.out.println("Enter an integer"); Scanner sc = new Scanner(System.in); int num = sc.nextInt(); if( (num<100) && (num>(-100)) && (num!=42) ) System.out.println(num); else return; } }  } answered 18 Dec '15, 15:05 1 accept rate: 0%

# include <iostream>

using namespace std;

int main()

{

int i;
do
{
cout << "Enter i : ";
cin >> i;
if (i==42 && i<100 && i>-100)
{
break;
}
else
{
cout << i;
}
} while (i != 42 && i<100 && i>-100);
return 0;


}

answered 22 Dec '16, 12:04 1
accept rate: 0%

@premang9270 you are not supposed to print things like "Enter i : " or something which is not specified in the problems statement.

The correct version of your code is ::

do {
cin >> i;
if(i == 42) {
break;
}
else {
cout << i;
}
}while(i != 42);


NOTE :: you are not given that the numbers lie in b/w -100 to 100 so don't use the condition i<100 && i>-100.

(22 Dec '16, 12:15)
2

read the last line of the question , that says digits must of two or one digits

(22 Dec '16, 16:39)

Yeah you are right still you don't need that condition to be checked.

(22 Dec '16, 17:19)

# include< conio.h >

using namespace std; int main() { int a,i; cout <<"enter integers" << endl; for( i=1 ; i<=1000 ; i++ ) { cin >> a[i]; if ( a[i]==42 ) { break; } } getch (); return 0; }

answered 09 Mar '17, 12:35 0★gagan22g
1
accept rate: 0%

# include<stdio.h>

main() { int a,i; printf("enter numbers and enter 42 to end"); for(i=0;i<100;i++) {scanf("%d",&a[i]);if(a[i]==42)break;else printf("%d",a[i]);} }

answered 13 May '17, 22:08 1
accept rate: 0%

 0 //C Solution by satadru97 #include int main(void) { int n; while(1) { scanf("%d",&n); if(n!=42) printf("%d\n",n); else break; } return 0; }  link This answer is marked "community wiki". answered 10 Jun '17, 08:54 1 accept rate: 0%
 0 int main() { int i; do { cout << "Enter i : "; cin >> i; if (i==42 && i<100 && i>-100) { break; } else { cout << i; } } while (i != 42 && i<100 && i>-100); return 0; } answered 16 Jun '17, 16:03 0★matta 1 accept rate: 0%

# include<stdio.h>

void main() { int i,n,a;

printf("\nenter total no's :"); scanf("%d",&n); printf("\nenter some input no's :"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } i=0; while(a[i]!='/0') { if(a[i]==42) {break; exit(1);} else { printf("%d",a[i]); } } }

answered 05 Jul '17, 13:55 1
accept rate: 0%

bro, the solutions are tested by an online judge. You should strictly obey the input/output format. For your case you are asking for total no of inputs and enter some new numbers these are unnecessary. just do an infinite loop beak it when u encounter 42.(for input output format codechef is providing sample cases below the problem) Happy coding..

(05 Jul '17, 14:18)
 0 Answer is hidden as author is suspended. Click here to view. answered 05 Jul '17, 15:02 2★raj79 (suspended) accept rate: 10%
 0 #include using namespace std; int main() { int n=0; while(n>=0) { cin>>n; if(n>99) break; else { if(n!=42) { cout<

//Code by swapnil1796

# include<stdio.h>

void main(){ int a; while(scanf("%d",&a) && a!=42) { printf("%d\n",a); } }

Runtime error. Please explain

answered 05 Sep '17, 20:58 1
accept rate: 0%

 0 import java.util.Scanner; class First{ public static void main(){ Scanner sc=new Scanner(int); int a=0; while(a!=42){ int a=sc.nextInt();}} answered 05 Oct '17, 17:54 1 accept rate: 0%

i am using this code in c language but it's giving runtime error ,can you please help?

# include<stdio.h>

void main() { int i=0; while(scanf("%d",&i)&&i!=42) { printf("\n%d",i); }

}

answered 12 Oct '17, 22:59 1
accept rate: 0%

 toggle preview community wiki:
Preview

### Follow this question

By Email:

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

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×1,688
×170
×43

question asked: 17 Dec '14, 14:23

question was seen: 9,248 times

last updated: 12 Oct '17, 22:59