Design a program using an array that lists even numbers and
odd numbers separately from the 12 numbers supplied by a user.
Answer Posted / prakash.
/* program to print even nums in even position,odd in odd
position*/
/* Ex: 2 1 3 4 output:2 1 4 3*/
/* work for almost all check it if any wrong*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[4],j=0,i;
int b[4],e=0,od=1;
clrscr();
for(i=0;i<4;i++)
{
printf("Enter A number : ");
scanf("%d",&a[i]);
}
for(i=0;i<4;i++)
{
if((a[i]%2)==0)
{
j=e;
b[j]=a[i];
e=j+2;
}
else
{
j=od;
b[j]=a[i];
od=od+2;
}
}
for(j=0;j<4;j++)
{
printf("%d\n",b[j]);
}
getch();
return;
}
| Is This Answer Correct ? | 4 Yes | 11 No |
Post New Answer View All Answers
What do you mean by dynamic memory allocation in c?
Write a simple code fragment that will check if a number is positive or negative.
How can I write a function analogous to scanf?
Differentiate between ordinary variable and pointer in c.
Which is the best website to learn c programming?
Write programs for String Reversal & Palindrome check
What do header files do?
What is pointer in c?
Explain what happens if you free a pointer twice?
How can I open a file so that other programs can update it at the same time?
Tell us the use of fflush() function in c language?
Explain the difference between malloc() and calloc() function?
Why is it that not all header files are declared in every C program?
Why do we use c for the speed of light?
What are the advantages of using linked list for tree construction?