TEST - Editorial

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

#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[i];
if ( a[i]==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[i]);if(a[i]==42)break;else printf("%d",a[i]);}
}

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

#include<stdio.h>

void main()
{
int i,n,a[20];

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

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…

spoj problem :slight_smile:

#include
using namespace std;

int main()
{
int n=0;
while(n>=0)
{

  cin>>n;
if(n>99)
break;
  else {

  if(n!=42)
  {
 cout<<n<<endl;


}
 else
  break;

  }
 }


   return 0;
  }

//Code by swapnil1796
#include<stdio.h>
void main(){
int a;
while(scanf("%d",&a) && a!=42)
{
printf("%d\n",a);
}
}

Runtime error. Please explain

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

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

}