why this is not giving right answer? it is running in my pc,but here it is giving pbl.

#include <stdio.h>
#include <stdlib.h>

int main()
{
int a[20],i,n;
printf(“how many no. u wanna enter?\n”);
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);

}
printf("after processing\n");
 for(i=0;i<n;i++)
{
    printf("%d\n",a[i]);
    if(a[i]==42)
        break;
}
return 0;

}

please remove any extra outputs like “how many no. u wanna enter?”. You should just take input and print the answer as output. Not a character extra.

1 Like

There are multiple errors in the program :

  1. Please donot output statements “how many no. u wanna enter” , etc . you just need to print the output of the program .
  2. There is no input for the total number of values . You need to take the input until 42 comes and when 42 comes , you stop taking input .
  3. You should check if the number is 42 , before printing .

Correcting the above errors , here is your corrected


[1] .


  [1]: http://www.codechef.com/viewsolution/4289553

Thanks,But How about this …

#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,i;
for(i=0;a!=42;i++)
{
scanf("%d",&a);

    }
    return 0;
}

ok.
thanks … means it will not gonna accept characters…

Yes that would also work , but you also need to print the numbers . here is the code : http://www.codechef.com/viewsolution/4290097

1 Like

If you find my answer useful , please upvote and accept it .