plz help me out with life universe and everything..it compiles ok in my compiler.but shows wrong answer here.

#include<stdio.h>
int main()
{
int a[10],i,num1,num2,var,var1,var2;

for(i=0;i<5;i++)
scanf("%d",&a[i]);

 var1=4;
var2=2;


for(i=0;i<5;i++)
{

if((a[i]/10)!=0 && (a[i]/10)<10)
{
    num2=a[i]%10;
    num1=a[i]/10;

    if(num1==var1)
    {
	if(num2==var2)
	{
	  
	    break;
	}
    }
    else
    printf("\n%d",a[i]);
}
else
printf("\n%d",a[i]);

}

return 0;
}

thats not what the problem statement says… read the statement again.

You have some small numbers as input(limit not defined), you have take input continuously and simultaneously print the number with the condition that it is not equal to 42. Also you have to stop taking input when you encounter 42.

pseudocode:

take a number as input
run an infinite loop
check if number==42:
      break
else
      print the inputted number
      take another input

Hey @the_flash

See what problem says is you’ll be given inputs and you’ll have to Stop processing input after reading in the number 42,

So First Thing as it shows there are 5 inputs, it doesn’t mean that actual test cases will also consist of only 5 inputs, It may be something like

10
20
5
6
5
1
23
10
42
40
41
45
.
.

So you have to code considering all test cases satisfying the constraints should pass your code.

Now coming to Algorithm for this problem:

use an infinite loop
    scan number
    check if it is equal to 42,
        if equal to 42:
            break
        else:
            print number

And Thats it…!!

And remember to print ‘\n’ after printing the number, i.e.,

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

Good Luck…!

Enjoy Coding and Welcome to Codechef… :slight_smile:

using System;

public class Test
{
public static void Main()
{
Test p = new Test();
p.InsertValues();
}

public void InsertValues()
{
	int[] numberArray = new int[5];
	for (int i = 0; i < numberArray.Length; i++)
	{
		numberArray[i] = Convert.ToInt16(Console.ReadLine());
	}

	Output(numberArray);
}

public void Output(int[] numberArray)
{
	for (int i = 0; i < numberArray.Length; i++)
	{
		if (numberArray[i] == 42)
		{
			break;
		}
		else
		{
			Console.WriteLine(numberArray[i]);
		}
	}
}

}
What is wrong with the code can anyone help ?

When codechef checks your program, it does not run it only on the given inputs but other inputs as well.So, after which iteration input will be 42 you donot know.
You should first get well versed with the difference in the use of for,while and do-while loops. Then decide for which loop will useful here.

while(1)

{

scanf("%d",&n);

if(n==42)break;

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

}