0

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();
}
3
Contributors
5
Replies
28
Views
2 Years
Discussion Span
Last Post by Moschops
0

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.

Edited by Moschops

0

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");
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.