Design a program using an array that lists even numbers and
odd numbers separately from the 12 numbers supplied by a user.
Answer Posted / vignesh1988i
A SMALL IMPLEMENTATION OF POINTERS
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],*ptr[50],count=0,n,flag=1;
printf("enter the max. elements to be entered :");
scanf("%d",&n);
int k=0;
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]%2!=0)
{
ptr[k]=&a[i];
count++;
k++;
}
else
flag=0;
printf("odd numbers :\n");
for(i=0;i<count;i++)
printf("%d\n",*(*(ptr+i)));
if(flag==0)
{
printf("even numbers :\n");
for(i=0;i<n;i++)
{
if(ptr[i]!=&a[i])
printf("%d\n",a[i]);
}
}
getch();
}
thank you
| Is This Answer Correct ? | 3 Yes | 15 No |
Post New Answer View All Answers
Differentiate abs() function from fabs() function.
How can I handle floating-point exceptions gracefully?
What are the application of void data type in c?
What is the difference between printf and scanf in c?
What are the types of unary operators?
In which language linux is written?
What would happen to X in this expression: X += 15; (assuming the value of X is 5)
What is c language in simple words?
What does void main return?
Why pointers are used?
Write the Program to reverse a string using pointers.
How can you be sure that a program follows the ANSI C standard?
What is the symbol indicated the c-preprocessor?
Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]
What functions are used in dynamic memory allocation in c?