TEST - Editorial

PROBLEM LINK:

Practice

Author: ADMIN

Editorialist: SUSHANT AGARWAL

DIFFICULTY:

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.

#include<iostream.h>

void main()
{
 int a,flag=0;
 do
 { 
  cin>>a;
  if(a<=99 && a>=(-99) && a!=42)
  {
   flag=1;
   cout<<a;
  }
 }while(flag==1); 
}

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);
    }
    
}

}

#include<stdio.h>
int main()
{int i,b[100];
for(i=0;i<100;i++)
{scanf("%d
“,&b*);
if(b*==42)
break;
else
printf(”%d
",b*);
}
return 0;}

#include<stdio.h>

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

#include<stdio.h>
#include<conio.h>
void main()
{
int x;
printf("
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);
}

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

/this is corect answer even tho sowing false/
#include <stdio.h>
int main ()
{
int n;
for (;n!=42;)
{
scanf ("%d",&n);

printf ("%d
",n);}
return 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);
	}

}

}

#include<stdio.h>
int main(void)
{
unsigned int num;
for(;printf("%d",scanf("%d",&num)!=42););
return(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[10];
      Scanner input = new Scanner(System.in);
      System.out.println(“enter the array”);
      for (int i =0;i<5;i++)
      {
      poda
      =input.nextInt();
      }

      System.out.printf("the output values are ");
      for (int i =0;i<5;i++)
      {
      if(poda*==42)
      {
      break;
      }
      System.out.println(poda*);
      }
      }

}

void main()
{
int i,a[6];
a[6]={1,42,84,7,8,9};
for(i=0;i<6;i++)
{
if(a*<=a[i+1])
{printf("%d",a*);
printf("
");
}else
break;

}
getch();
}

#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;
}

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
while(1)
{
printf(“Enter the number:”);
scanf("%d",&n);
if(n==42)
break;
printf("%d",&n);
}
}

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");
}

}

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;
			}
}

}

include

using namespace std;

int main()

{

int i;
do
{
    cout <> i;
    if (i==42 && i<100 && i>-100)
    {
        break;
    }
    else
    {
        cout <-100);
return 0;

}

#include< iostream >
#include< conio.h >
using namespace std;
int main()
{
int a[1000],i;
cout <<“enter integers” << endl;
for( i=1 ; i<=1000 ; i++ )
{
cin >> a*;
if ( a*==42 )
{
break;
}
}
getch ();
return 0;
}

#include<stdio.h>
main()
{
int a[100],i;
printf(“enter numbers and enter 42 to end”);
for(i=0;i<100;i++)
{scanf("%d",&a*);if(a*==42)break;else printf("%d",a*);}
}

//C Solution by satadru97
#include<stdio.h>
int main(void)
{
int n;
while(1)
{
scanf("%d",&n);
if(n!=42)
printf("%d
",n);
else
break;
}
return 0;
}