C program to remove even numbers and fill it with zero
Input array 1,2,3,4,5,6
Output 1,3,5,0,0,0

#include<stdio.h>
void main()

int i,j,k,n=6,a[]={1,2,3,4,5,6};
clrscr();
for(i=0;i<n;i++)
{
if(a[i]%2==0)
{
a[i]=-1;
}
else
printf("%d",a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]==-1)
printf("0");
 }
getch();
}
Re: C program to remove even numbers and fill it with zero 80 80

Can you do the loop step 2? Would be more efficient.

Re: C program to remove even numbers and fill it with zero 80 80

You say it will remove the even numbers and zero fill, but it doesn't. At the start the array looks like this:
{1,2,3,4,5,6}
and at the end it looks like this:
{1,-1,3,-1,5,-1}

Even numbers not removed (but instead replaced with -1), array not zero-filled. The program does not do what it is supposed to.

Re: C program to remove even numbers and fill it with zero 80 80

but at last the expected output getting..

Re: C program to remove even numbers and fill it with zero 80 80

but at last the expected output getting..

If that's all that matters, here's the programme in a much more efficient form:

#include <stdio.h>

int main()
{
  printf("1 3 5 0 0 0");
}
Re: C program to remove even numbers and fill it with zero 80 80

As it is, this is a ZOHO interview question, as seen here:
https://www.daniweb.com/software-development/c/threads/456728/zoho-interview-question
and they certainly wouldn't accept an answer that didn't actually do what it was supposed to, but instead output something to make the user think it was working.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.