#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]);
}
}
}
spoj problem
#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);
}
}
Donāt give statements like āEnter numberā etc. Directly take input and print output in the given format.
@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.
read the last line of the question , that says digits must of two or one digits
Yeah you are right still you donāt need that condition to be checked.
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ā¦
#include<stdio.h>
int main()
{
while(1)
{
int a;
scanf("%d",&a);
if(a<=99&&a>=-99&&a!=42)
printf("%d\n", a);
else
break;
}
return 0;
}
infinite loop
this is my code in c its showing wrong after submission even if custom input and output are correct
#include <stdio.h>
int main(void) {
int a[100], i;
for(i = 0 ; i < 100 ; i++)
{
scanf("%d\n", &a[i]);
}
for ( i = 0 ; i < 100 ; i++)
{
printf("%d\n", a[i]);
if(a[i] == 42)
{
break;
}
}
return 0;
}
You are only running for 100 cases. You have to run till you get 42