Unexpected output in array
-
Hi All, //program to place even numbers in one array and odd numbers in another array PFA code. #include void main() { int array[20],array1[20],array2[20],i,n,j; printf("enter how many array elements\n"); scanf("%d",&n); for(i=0;i
-
Hi All, //program to place even numbers in one array and odd numbers in another array PFA code. #include void main() { int array[20],array1[20],array2[20],i,n,j; printf("enter how many array elements\n"); scanf("%d",&n); for(i=0;i
You are putting holes in your arrays of even and odd elements. In order to avoid that, you need to maintain two separate variables to keep track of how many even and odd items have been added so far. Try
#include
#define SIZE 20
int main()
{
int items, odd_items, even_items;
int array[SIZE], odd[SIZE], even[SIZE];
printf("enter how many array elements\n");scanf("%d",&items);
odd_items = even_items = 0;
for (int n=0; n
"In testa che avete, Signor di Ceprano?"
-- Rigoletto -
Hi All, //program to place even numbers in one array and odd numbers in another array PFA code. #include void main() { int array[20],array1[20],array2[20],i,n,j; printf("enter how many array elements\n"); scanf("%d",&n); for(i=0;i
Did you try
scanf("%d",array[i]);
without ampersand? Besides, main() is int, not void.
-
You are putting holes in your arrays of even and odd elements. In order to avoid that, you need to maintain two separate variables to keep track of how many even and odd items have been added so far. Try
#include
#define SIZE 20
int main()
{
int items, odd_items, even_items;
int array[SIZE], odd[SIZE], even[SIZE];
printf("enter how many array elements\n");scanf("%d",&items);
odd_items = even_items = 0;
for (int n=0; n
"In testa che avete, Signor di Ceprano?"
-- Rigoletto5, but you should get 10 for looking at code formatted this way. :-D
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
5, but you should get 10 for looking at code formatted this way. :-D
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing.