Hi
Am new to programming world and this is my first attempt.
Could some one tell me what mistake am making in this pgm?
include
int i, num[5];
int main()
{
for (i=0;i<5;i++)
{
scanf("%d",&num[i]);
}
for (i=0;i<5 && num[i]!=42;i++)
{
printf("%d\n",num[i]);
}
return 0;
}
This works fine in terminal but not a right ans in SPOJ.
Just thought I'd share mine since I haven't seen it in this topic yet.
#include <stdio.h>
int main(void) {
char x[3];
while(atoi(gets(x))!=42)puts(x);
return 0;
}
Alternatively with fgets() and fputs():
#include <stdio.h>
int main(void)
{
char x[4];
while (atoi(fgets(x,4,stdin))!=42)
{
fputs(x,stdout);
}
return 0;
}
@leppy, is it the size of the character array? I believe I made the size of my array 3 in my original version, but I was just playing around to see if I could get away with buffer overflow. ^^
Sorry I forgot to change it back. I edited the post to make the size of the array 3, which should account for the max 2 characters per line (not counting newline).
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int arr[10000];
int count=0,i=0,flag=1;
printf("Enter Input:");
while(flag)
{
scanf("%d",&arr[i]);
if(arr[i]==42)
flag=0;
else
flag=1;
i++;
count++;
}
for(i=0;i<count-1;i++)
{
printf("%d\n",arr[i]);
}
return 0;
}
can you plz explain me what is wrong with this code because it gives the same output that is required but i do no understand they considered it as wrong answer.