By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Why is garbage value coming while executing my c programm ?

P: 1
/*programming for partition the elements of the array so that all the even numbers move to one side and odd numbers to the other side of the array.*/

#include<stdio.h>
int main()
{
int i,t,p,x,z,temp;
printf("enter the size of array\n");
scanf("%d",&i);

int a[i];
printf("enter the element of array\n");

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

for(x=0;x<i;x++)
{
for(p=0;p<i;p++)
{
if (a[p]%2==1)
{
temp=a[p];
a[p]=a[p+1];
a[p+1]=temp;
}
}
}
printf("required array:");
for(z=0;z<i;z++)

printf("%d\n",a[z]);
return 0;
}
Aug 27 '10 #1
Share this Question
Share on Google+
1 Reply


100+
P: 687
Because you read from uninitialized memory.
Aug 27 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.