41 / 92
May 2014

output is correct but it was showing run-time error

include

void main()
{
int j,i;
for(i=0;i<100;i++)
{
scanf("%d",&j);
if(j==42) break;
printf("%d",j);
}
}

Please use code tags when posting code.

For the input:

10
23
42
3
10

Your code returns:

1023

It should return:

10
23

Why are you using 100? There is no indication as to how many numbers are in the input.

2 months later

Why i am getting compilation error??
[code]

include

include

int main()
{
int n;
while(1)
{
scanf("%d",&n);
if(n>=0&&n<100&&n!=42)

        printf("%d\n",n);
    else
        exit(0);

}

return 0;

}

If you click on where it says "Compilation Error" it will actually list you the compilation error.

1 month later

Every one is writing code only for the above input only.
It should not be like that na.
We have to sort all the numbers before 42 in ascending order (as mentioned in the question...."More precisely... rewrite small numbers from input to output").
Then we have to print all the numbers.
why everyone is writing the code without sorting?
or
Any problem with my way of understanding the question(let me know the correct way)??

and

why admin did consider the two digit input case as the program can accept any number na..????

Thanks in advance smile smile

There is nothing in this problem statement that says to sort the numbers.

"More precisely..." means that the statement to follow will make the previous statement more precise.

"rewrite small numbers from input to output"
Input is where the numbers are read from. Output is where the numbers get printed to. Rewrite means to copy. The problem is asking you to read the numbers from input and write them to output. Stop when the number is 42.

Keeping the numbers one or two digits keeps the problem simple. It also allows for some creative solutions.

If you need more clarification, please post again.

I have only one doubt now.
Can i give the input sequence like 88 1 99 or 99 55 1 (small number followed by bigger number)..??
if not then y??

Thanks in Advance

Yes those are legal input. The numbers can be in any order. The only requirement is that they be only one or two digits and the input must contain a 42.

Know that you do not choose the input that the judge will use. Your solution must work for all possible input that the judge will give you.

Can i know the output for the following inputs(asking only for my clarity...don't mind.... confused )

1.) 1 12 453 32 45 67 89 987 42
2.) 123 123 123 42
3.)98 56 45 34 23 19 12 67 89 123 454 87 90 1 42

Thanks in Advance

None of those test cases are valid. The judge will not provide invalid test cases.

27 days later

i wrote the following code
and in my terminal im getting the desired output but for some reason in the SPOJ its showing wrong answer
please help !! im net to SPOJ;

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

Your code does not return the correct output for the sample input.

For this input:

1
2
88
42
99

Your code will print:

1288

The correct output is:

1
2
88

The difficulty that you are having is caused by the fact that you are using the console for input. The console allows you to type input to stdin as well as display output from stdout.

If you redirect your stdin and stdout to a file then you will accurately see what is being entered from stdin and being output to stdout.

To fix your output issue you should change your printf statement by adding a newline character to the end of it:

printf("%d\n",a);

Why have you chosen these conditions for your while loop?

while(a>0&&a!=42)

I got the same output as noix by implementing the following code but i get 'wrong answer' when i submit it on spoj please help me out
The Code:

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

The Code When ran in ideone gave same result!

http://ideone.com/jKSYau4
http://ideone.com/XyJUag9

1 month later

I just can't figure put what is the problem with my code -

#include<stdio.h>
int main()
{
	int i, k[5];
    i=0;

while(i != 5)
{
scanf("%d", &k[i]);
i++;

}

i=0;

while (i !=5 )
{
	printf("%d", k[i]);
	i++;
	
	if( k[i] < k[i-1])
	{break;}
	else{printf("\n");}

}


return 0;
}

Thank you.

1 month later

Why is my source code not accepted even though the expected output is obtained?

#include <stdio.h>
int main(void){
	int x;
	for(;;)
	{
		scanf("%d",&x);
		if (x>0&&x!=42)
			printf("%d\n",x);
		else
			break;
	}
	return 0;
}

What's wrong with zero?

0
0
0
0
0
0
0
42
10
11
12

Thanks. I removed the x>0 condition and the code was accepted. But the program at the start of this thread is accepted even though it has x>0 condition. Why?

#include <stdio.h>
int main(void) {
  int x;
  for(; scanf("%d",&x) > 0 && x != 42; printf("%d\n", x));
  return 0;
}